From 75026c9b7ac81ee184bab8516f814c3522fbde11 Mon Sep 17 00:00:00 2001 From: mohe Date: Fri, 14 Aug 2026 09:31:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ocg=5Frouter=E7=A9=BA=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8D=A2key=E2=80=94=E2=80=94=5Fforward=5Fre?= =?UTF-8?q?quest=E6=A3=80=E6=B5=8Bcontent=E4=B8=BA=E7=A9=BA=E2=86=92?= =?UTF-8?q?=E8=BF=94=E5=9B=9Eempty=5Fcontent=E2=86=92=5Fproxy=5Fchat?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8D=A2=E4=B8=8B=E4=B8=80=E4=B8=AAkey?= =?UTF-8?q?=E9=87=8D=E8=AF=95(=E4=B8=8D=E5=86=B7=E5=8D=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway/scripts/ocg_router.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gateway/scripts/ocg_router.py b/gateway/scripts/ocg_router.py index c8680c4..78337ea 100644 --- a/gateway/scripts/ocg_router.py +++ b/gateway/scripts/ocg_router.py @@ -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}