Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: chatml-noforce-roles wrapper + cli fix (#738)
Charles Packer653693c39872
diff --git a/memgpt/interface.py b/memgpt/interface.pyindex e0b1b6f5f..da61fecae 100644--- a/memgpt/interface.py+++ b/memgpt/interface.py@@ -159,8 +159,8 @@ class CLIInterface(AgentInterface):if match:function_name = match.group(1)function_args = match.group(2)- if function_name in ["archival_memory_insert", "archival_memory_search"]:- if function_name == "archival_memory_insert":+ if function_name in ["archival_memory_insert", "archival_memory_search", "core_memory_replace", "core_memory_append"]:+ if function_name in ["archival_memory_insert", "core_memory_append", "core_memory_replace"]:print_function_message("🧠", f"updating memory with {function_name}")elif function_name == "archival_memory_search":print_function_message("🧠", f"searching memory with {function_name}")diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.pyindex 76c17812f..49e2c837d 100644--- a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py+++ b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py@@ -40,6 +40,7 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):assistant_prefix_extra='\n{\n "function":',assistant_prefix_extra_first_message='\n{\n "function": "send_message",',allow_custom_roles=True, # allow roles outside user/assistant+ use_system_role_in_user=False, # use the system role on user messages that don't use "type: user_message"# allow_function_role=True, # use function role for function replies?allow_function_role=False, # use function role for function replies?no_function_role_role="assistant", # if no function role, which role to use?@@ -56,6 +57,7 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):# role-basedself.allow_custom_roles = allow_custom_roles+ self.use_system_role_in_user = use_system_role_in_userself.allow_function_role = allow_function_role# extras for when the function role is disallowedself.no_function_role_role = no_function_role_role@@ -198,6 +200,13 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):role_str = message["name"].strip().lower() if (self.allow_custom_roles and "name" in message) else message["role"]msg_str = self._compile_user_message(message)+ if self.use_system_role_in_user:+ try:+ msg_json = json.loads(message["content"])+ if msg_json["type"] != "user_message":+ role_str = "system"+ except:+ passprompt += f"\n<|im_start|>{role_str}\n{msg_str.strip()}<|im_end|>"elif message["role"] == "assistant":diff --git a/memgpt/local_llm/utils.py b/memgpt/local_llm/utils.pyindex cb19c914d..3c1f17a68 100644--- a/memgpt/local_llm/utils.py+++ b/memgpt/local_llm/utils.py@@ -50,6 +50,8 @@ def get_available_wrappers() -> dict:# New chatml-based wrappers"chatml": chatml.ChatMLInnerMonologueWrapper(),"chatml-noforce": chatml.ChatMLOuterInnerMonologueWrapper(),+ # "chatml-noforce-sysm": chatml.ChatMLOuterInnerMonologueWrapper(use_system_role_in_user=True),+ "chatml-noforce-roles": chatml.ChatMLOuterInnerMonologueWrapper(use_system_role_in_user=True, allow_function_role=True),# With extra hints"chatml-hints": chatml.ChatMLInnerMonologueWrapper(assistant_prefix_hint=True),"chatml-noforce-hints": chatml.ChatMLOuterInnerMonologueWrapper(assistant_prefix_hint=True),