Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support system message for chatml wrapper #2187

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion letta/local_llm/llm_chat_completion_wrappers/chatml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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:
Expand Down Expand Up @@ -208,7 +209,9 @@ def chat_completion_to_prompt(self, messages, functions, first_message=False, fu

# 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
Expand All @@ -231,6 +234,15 @@ def chat_completion_to_prompt(self, messages, functions, first_message=False, fu

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"]
Expand Down
Loading