import re from datetime import datetime from typing import Optional from IPython.display import HTML, display from sqlalchemy.testing.plugin.plugin_base import warnings from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL, INNER_THOUGHTS_CLI_SYMBOL def pprint(messages): """Utility function for pretty-printing the output of client.send_message in notebooks""" css_styles = """ """ html_content = css_styles + "
" for message in messages: date_str = message["date"] date_formatted = datetime.fromisoformat(date_str.replace("Z", "+00:00")).strftime("%Y-%m-%d %H:%M:%S") if "function_return" in message: return_string = message["function_return"] return_status = message["status"] html_content += f"

🛠️ [{date_formatted}] Function Return ({return_status}):

" html_content += f"

{return_string}

" elif "internal_monologue" in message: html_content += f"

{INNER_THOUGHTS_CLI_SYMBOL} [{date_formatted}] Internal Monologue:

" html_content += f"

{message['internal_monologue']}

" elif "function_call" in message: html_content += f"

🛠️ [[{date_formatted}] Function Call:

" html_content += f"

{message['function_call']}

" elif "assistant_message" in message: html_content += f"

{ASSISTANT_MESSAGE_CLI_SYMBOL} [{date_formatted}] Assistant Message:

" html_content += f"

{message['assistant_message']}

" html_content += "
" html_content += "
" display(HTML(html_content)) def derive_function_name_regex(function_string: str) -> Optional[str]: # Regular expression to match the function name match = re.search(r"def\s+([a-zA-Z_]\w*)\s*\(", function_string) if match: function_name = match.group(1) return function_name else: warnings.warn("No function name found.") return None