feat: ocg_router空输出自动换key——_forward_request检测content为空→返回empty_content→_proxy_chat自动换下一个key重试(不冷却)

This commit is contained in:
2026-08-14 09:31:07 +08:00
parent 6a5c08a5df
commit 75026c9b7a
+12 -1
View File
@@ -584,8 +584,19 @@ class RouterHandler(BaseHTTPRequestHandler):
err_body = resp.read().decode("utf-8", errors="replace")[:500]
return {"ok": False, "status": status, "error": f"HTTP {status}: {err_body}"}
# 透传响应
# 透传响应 + 空输出检测(2026-08-14 老莫:空输出自动换 key)
resp_body = resp.read()
if not is_stream:
# 非流式:解析 JSON 检测空输出
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"}
except Exception:
pass # 解析失败不阻断(正常透传)
self._send_response(status, dict(resp.headers), resp_body)
return {"ok": True}