Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

-LAN-1db14793fa40
diff --git a/api/core/model_runtime/model_providers/anthropic/llm/llm.py b/api/core/model_runtime/model_providers/anthropic/llm/llm.py
index 79701e4ea4f..b5de02193b2 100644
--- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py
+++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py
@@ -461,7 +461,15 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
first_loop = True
for message in prompt_messages:
if isinstance(message, SystemPromptMessage):
- message.content = message.content.strip()
+ 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