fix: preserve empty-string reasoning_content instead of coercing to None

Custom providers (e.g. DeepSeek) may return reasoning_content as an
empty string "" to explicitly indicate no reasoning occurred. The
previous truthiness checks (, ) treated "" as falsy
and converted it to None, which caused the field to be dropped from
the message history entirely. Providers that require reasoning_content
on all assistant messages then rejected subsequent requests.

Replace truthiness checks with identity checks () so that
empty-string reasoning_content is preserved as-is. The streaming path
is unchanged since an empty join genuinely means no chunks received.

Fixes #4105
This commit is contained in:
michaelxer
2026-06-08 01:08:27 +08:00
committed by Xubin Ren
parent 4f5f965f09
commit 05de864f5b
2 changed files with 30 additions and 5 deletions
+4 -4
View File
@@ -999,7 +999,7 @@ class OpenAICompatProvider(LLMProvider):
if not content and msg0.get("reasoning") and self._spec and self._spec.reasoning_as_content:
content = self._extract_text_content(msg0.get("reasoning"))
reasoning_content = msg0.get("reasoning_content")
if not reasoning_content and msg0.get("reasoning"):
if reasoning_content is None and msg0.get("reasoning"):
reasoning_content = self._extract_text_content(msg0.get("reasoning"))
for ch in choices:
ch_map = self._maybe_mapping(ch) or {}
@@ -1011,7 +1011,7 @@ class OpenAICompatProvider(LLMProvider):
finish_reason = str(ch_map["finish_reason"])
if not content:
content = self._extract_text_content(m.get("content"))
if not reasoning_content:
if reasoning_content is None:
reasoning_content = m.get("reasoning_content")
parsed_tool_calls = []
@@ -1074,8 +1074,8 @@ class OpenAICompatProvider(LLMProvider):
function_provider_specific_fields=fn_prov,
))
reasoning_content = getattr(msg, "reasoning_content", None) or None
if not reasoning_content and getattr(msg, "reasoning", None):
reasoning_content = getattr(msg, "reasoning_content", None)
if reasoning_content is None and getattr(msg, "reasoning", None):
reasoning_content = msg.reasoning
return LLMResponse(