Skip to content

Commit 07b37b9

Browse files
SoulterCopilot
andauthored
fix: handle empty reasoning content for DeepSeek v4 models (#7823)
Co-authored-by: Copilot <copilot@github.com>
1 parent bbda1e6 commit 07b37b9

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

astrbot/core/provider/sources/openai_source.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,11 @@ def _finally_convert_payload(self, payloads: dict) -> None:
982982
"""Finally convert the payload. Such as think part conversion, tool inject."""
983983
model = payloads.get("model", "").lower()
984984
is_gemini = "gemini" in model
985+
deepseek_reasoning_models = {"deepseek-v4-pro", "deepseek-v4-flash"}
986+
is_deepseek_v4_reasoning = (
987+
model in deepseek_reasoning_models
988+
or "api.deepseek.com" in self.client.base_url.host
989+
)
985990

986991
for message in payloads.get("messages", []):
987992
if message.get("role") == "assistant" and isinstance(
@@ -997,7 +1002,14 @@ def _finally_convert_payload(self, payloads: dict) -> None:
9971002
# Some providers (Grok, etc.) reject empty content lists.
9981003
# When all parts were think blocks, fall back to None.
9991004
message["content"] = new_content or None
1000-
if reasoning_content:
1005+
if is_deepseek_v4_reasoning and not reasoning_content:
1006+
logger.info(
1007+
"Deepseek v4 model requires non-empty reasoning content, but got empty. Setting to 'none' to satisfy the requirement."
1008+
)
1009+
# Deepseek models require the field on assistant
1010+
# history messages, even when the reasoning content is empty.
1011+
message["reasoning_content"] = "none"
1012+
elif reasoning_content:
10011013
message["reasoning_content"] = reasoning_content
10021014

10031015
# Gemini 的 function_response 要求 google.protobuf.Struct(即 JSON 对象),

0 commit comments

Comments
 (0)