diff --git a/gateway/scripts/ocg_router.py b/gateway/scripts/ocg_router.py index dbea9e0..741320e 100644 --- a/gateway/scripts/ocg_router.py +++ b/gateway/scripts/ocg_router.py @@ -612,10 +612,21 @@ 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(): - log.warning("empty content detected via key, retrying next key") - return {"ok": False, "status": 0, "error": "empty_content"} + 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: pass # 解析失败不阻断(正常透传) self._send_response(status, dict(resp.headers), resp_body)