fix(anthropic_llm): Ignore non-text parts in the system prompt. (#11107)

This commit is contained in:
-LAN- 2024-11-26 13:31:40 +08:00 committed by GitHub
parent cbb4e95928
commit 1db14793fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -461,7 +461,15 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
first_loop = True
for message in prompt_messages:
if isinstance(message, SystemPromptMessage):
if isinstance(message.content, str):
message.content = message.content.strip()
elif isinstance(message.content, list):
# System prompt only support text
message.content = "".join(
c.data.strip() for c in message.content if isinstance(c, TextPromptMessageContent)
)
else:
raise ValueError(f"Unknown system prompt message content type {type(message.content)}")
if first_loop:
system = message.content
first_loop = False