Skip to content

Commit

Permalink
fix: patched anthropic system message in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker committed Dec 9, 2024
1 parent b1015c0 commit d3a4bb3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion letta/schemas/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,20 @@ def add_xml_tag(string: str, xml_tag: Optional[str]):
return f"<{xml_tag}>{string}</{xml_tag}" if xml_tag else string

if self.role == "system":
raise ValueError(f"Anthropic 'system' role not supported")
# NOTE: this is not for system instructions, but instead system "events"

assert all([v is not None for v in [self.text, self.role]]), vars(self)
# Two options here, we would use system.package_system_message,
# or use a more Anthropic-specific packaging ie xml tags
user_system_event = add_xml_tag(string=f"SYSTEM ALERT: {self.text}", xml_tag="event")
anthropic_message = {
"content": user_system_event,
"role": "user",
}

# Optional field, do not include if null
if self.name is not None:
anthropic_message["name"] = self.name

elif self.role == "user":
assert all([v is not None for v in [self.text, self.role]]), vars(self)
Expand Down

0 comments on commit d3a4bb3

Please sign in to comment.