From 47ea036a810451b2717d47350c1fc9b8a6f49ad6 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 27 Apr 2026 11:45:42 +0800 Subject: [PATCH] fix: add reasoning_content field for DeepSeek v4 models in assistant messages --- astrbot/core/provider/sources/openai_source.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 03dcf6338..512e47233 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -990,6 +990,11 @@ class ProviderOpenAIOfficial(Provider): """Finally convert the payload. Such as think part conversion, tool inject.""" model = payloads.get("model", "").lower() is_gemini = "gemini" in model + deepseek_reasoning_models = {"deepseek-v4-pro", "deepseek-v4-flash"} + is_deepseek_v4_reasoning = ( + model in deepseek_reasoning_models + or "api.deepseek.com" in self.client.base_url.host + ) for message in payloads.get("messages", []): if message.get("role") == "assistant" and isinstance( message.get("content"), list @@ -1009,6 +1014,15 @@ class ProviderOpenAIOfficial(Provider): if reasoning_content_present: message["reasoning_content"] = reasoning_content + if ( + message.get("role") == "assistant" + and is_deepseek_v4_reasoning + and "reasoning_content" not in message + ): + # DeepSeek v4 reasoning models require the field on assistant + # history messages, even when the reasoning content is empty. + message["reasoning_content"] = "" + # Gemini 的 function_response 要求 google.protobuf.Struct(即 JSON 对象), # 纯文本会触发 400 Invalid argument,需要包一层 JSON。 if is_gemini and message.get("role") == "tool":