fix: empty_content false-positive on reasoning models — deepseek-v4-flash/pro return content in reasoning_content; only treat as empty when no content AND no reasoning AND not finish_reason=length
This commit is contained in:
@@ -612,8 +612,19 @@ class RouterHandler(BaseHTTPRequestHandler):
|
||||
try:
|
||||
import json as _json
|
||||
d = _json.loads(resp_body.decode("utf-8", errors="replace"))
|
||||
content = d.get("choices", [{}])[0].get("message", {}).get("content", "")
|
||||
if not content or not str(content).strip():
|
||||
msg = d.get("choices", [{}])[0].get("message", {}) or {}
|
||||
content = msg.get("content", "")
|
||||
# 推理模型(deepseek-v4-flash/pro 等)回复在 reasoning_content,
|
||||
# content 可能为空(尤其 max_tokens 小时 token 全用于推理)——
|
||||
# 有 reasoning_content 或 finish_reason=length 都视为正常,不算空输出
|
||||
reasoning = msg.get("reasoning_content", "")
|
||||
finish_reason = d.get("choices", [{}])[0].get("finish_reason", "")
|
||||
has_reasoning = bool(reasoning and str(reasoning).strip())
|
||||
if (not content or not str(content).strip()) and not has_reasoning:
|
||||
if finish_reason == "length":
|
||||
# max_tokens 截断,content 可能为空但属于正常响应
|
||||
log.warning("content empty but finish_reason=length (truncated), passing through")
|
||||
else:
|
||||
log.warning("empty content detected via key, retrying next key")
|
||||
return {"ok": False, "status": 0, "error": "empty_content"}
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user