feat: ocg_router空输出自动换key——_forward_request检测content为空→返回empty_content→_proxy_chat自动换下一个key重试(不冷却)
This commit is contained in:
@@ -584,8 +584,19 @@ class RouterHandler(BaseHTTPRequestHandler):
|
|||||||
err_body = resp.read().decode("utf-8", errors="replace")[:500]
|
err_body = resp.read().decode("utf-8", errors="replace")[:500]
|
||||||
return {"ok": False, "status": status, "error": f"HTTP {status}: {err_body}"}
|
return {"ok": False, "status": status, "error": f"HTTP {status}: {err_body}"}
|
||||||
|
|
||||||
# 透传响应
|
# 透传响应 + 空输出检测(2026-08-14 老莫:空输出自动换 key)
|
||||||
resp_body = resp.read()
|
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)
|
self._send_response(status, dict(resp.headers), resp_body)
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user