Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: support system message for chatml wrapper (#2187)

Sarah Wooders213749a177db
diff --git a/letta/local_llm/llm_chat_completion_wrappers/chatml.py b/letta/local_llm/llm_chat_completion_wrappers/chatml.py
index 82155d955..baa159232 100644
--- a/letta/local_llm/llm_chat_completion_wrappers/chatml.py
+++ b/letta/local_llm/llm_chat_completion_wrappers/chatml.py
@@ -3,6 +3,7 @@ from letta.local_llm.json_parser import clean_json
from letta.local_llm.llm_chat_completion_wrappers.wrapper_base import (
LLMChatCompletionWrapper,
)
+from letta.schemas.enums import MessageRole
from letta.utils import json_dumps, json_loads
PREFIX_HINT = """# Reminders:
@@ -208,7 +209,9 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function", "tool"], message
+ # check that message["role"] is a valid option for MessageRole
+ # TODO: this shouldn't be necessary if we use pydantic in the future
+ assert message["role"] in [role.value for role in MessageRole]
if message["role"] == "user":
# Support for AutoGen naming of agents
@@ -231,6 +234,15 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):
prompt += f"\n<|im_start|>{role_str}\n{msg_str.strip()}<|im_end|>"
+ elif message["role"] == "system":
+
+ role_str = "system"
+ msg_str = self._compile_system_message(
+ system_message=message["content"], functions=functions, function_documentation=function_documentation
+ )
+
+ prompt += f"\n<|im_start|>{role_str}\n{msg_str.strip()}<|im_end|>"
+
elif message["role"] in ["tool", "function"]:
if self.allow_function_role:
role_str = message["role"]