diff --git a/astrbot/core/provider/sources/anthropic_source.py b/astrbot/core/provider/sources/anthropic_source.py index d982af2e4..a55a3a0a1 100644 --- a/astrbot/core/provider/sources/anthropic_source.py +++ b/astrbot/core/provider/sources/anthropic_source.py @@ -448,8 +448,14 @@ class ProviderAnthropic(Provider): }, ) - # 如果只有一个文本块且没有图片,返回简单格式以保持向后兼容 - if len(content) == 1 and content[0]["type"] == "text": + # 如果只有主文本且没有额外内容块和图片,返回简单格式以保持向后兼容 + if ( + text + and not extra_content_blocks + and not image_urls + and len(content) == 1 + and content[0]["type"] == "text" + ): return {"role": "user", "content": content[0]["text"]} # 否则返回多模态格式 diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index 487acd431..614c83aad 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -839,8 +839,14 @@ class ProviderGoogleGenAI(Provider): }, ) - # 如果只有文本且没有额外内容块,返回简单格式以保持向后兼容 - if len(content_blocks) == 1 and content_blocks[0]["type"] == "text": + # 如果只有主文本且没有额外内容块和图片,返回简单格式以保持向后兼容 + if ( + text + and not extra_content_blocks + and not image_urls + and len(content_blocks) == 1 + and content_blocks[0]["type"] == "text" + ): return {"role": "user", "content": content_blocks[0]["text"]} # 否则返回多模态格式 diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 97bb992e7..fcd2e0e32 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -662,8 +662,14 @@ class ProviderOpenAIOfficial(Provider): }, ) - # 如果只有文本且没有额外内容块,返回简单格式以保持向后兼容 - if len(content_blocks) == 1 and content_blocks[0]["type"] == "text": + # 如果只有主文本且没有额外内容块和图片,返回简单格式以保持向后兼容 + if ( + text + and not extra_content_blocks + and not image_urls + and len(content_blocks) == 1 + and content_blocks[0]["type"] == "text" + ): return {"role": "user", "content": content_blocks[0]["text"]} # 否则返回多模态格式 diff --git a/packages/astrbot/process_llm_request.py b/packages/astrbot/process_llm_request.py index 532aac219..f787970c7 100644 --- a/packages/astrbot/process_llm_request.py +++ b/packages/astrbot/process_llm_request.py @@ -242,6 +242,6 @@ class ProcessLLMRequest: # 统一包裹所有系统提醒 if system_parts: system_content = ( - "" + "".join(system_parts) + "" + "" + "\n".join(system_parts) + "" ) req.extra_content_blocks.append({"type": "text", "text": system_content})