fix: anthropic thinking tag nesting bug (#1548)

This commit is contained in:
cthomas
2025-04-03 11:51:08 -07:00
committed by GitHub
parent 6a6fd28517
commit cf5da62021

View File

@@ -670,6 +670,9 @@ class Message(BaseMessage):
def add_xml_tag(string: str, xml_tag: Optional[str]):
# NOTE: Anthropic docs recommends using <thinking> tag when using CoT + tool use
if f"<{xml_tag}>" in string and f"</{xml_tag}>" in string:
# don't nest if tags already exist
return string
return f"<{xml_tag}>{string}</{xml_tag}" if xml_tag else string
if self.role == "system":