From efd8baaeff0fdc0c25b33651c6d4a3561283a30f Mon Sep 17 00:00:00 2001 From: hmo Date: Wed, 22 Jul 2026 13:54:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A9=BA=E8=BE=93=E5=87=BA=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=81=87=E6=88=90=E5=8A=9F=E2=80=94=E2=80=94=E5=8D=87?= =?UTF-8?q?=E7=BA=A7pro=E4=BB=8D=E7=A9=BA=E6=97=B6=E8=90=BD=E5=88=B0?= =?UTF-8?q?=E5=A4=96=E5=BE=AA=E7=8E=AF=E5=88=87=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/llm_client.py | 51 +++++++++++++++------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/deploy/profile-scripts/llm_client.py b/deploy/profile-scripts/llm_client.py index 86a958ee..438d04e7 100644 --- a/deploy/profile-scripts/llm_client.py +++ b/deploy/profile-scripts/llm_client.py @@ -224,29 +224,34 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150, ok, result = _post(ch_url, ch_headers, payload, timeout) elapsed = time.monotonic() - t0 if ok: - # ── 空输出升级:flash 对部分 prompt 稳定返回空(688617 实测), - # 先同 key 换 FALLBACK_MODEL(pro) 重试;仍空则让外循环切下一个 key ── - if not result.strip() and model_name != FALLBACK_MODEL and ch_name.startswith("ocg"): - print(f" [LLM] {ch_name} {model_name} 空输出({elapsed:.1f}s)," - f"升级 {FALLBACK_MODEL} 重试...", flush=True) - esc_payload = json.dumps({ - "model": FALLBACK_MODEL, "messages": messages, - "max_tokens": max_tokens, - }).encode() - try: - ok2, result2 = _post(ch_url, ch_headers, esc_payload, timeout) - total_attempts += 1 - if ok2 and result2.strip(): - print(f" [LLM] 升级 {FALLBACK_MODEL} 成功, 输出{len(result2)}字", flush=True) - return { - "ok": True, "content": result2, "error": None, - "model": FALLBACK_MODEL, - "elapsed": time.monotonic() - t_start, - "attempts": total_attempts, "channel": ch_name + "+esc", - } - print(f" [LLM] {ch_name} 升级 {FALLBACK_MODEL} 仍空/失败", flush=True) - except Exception as e2: - print(f" [LLM] 升级 {FALLBACK_MODEL} 异常: {str(e2)[:100]}", flush=True) + # ── 空输出视为失败:先同 key 升 FALLBACK_MODEL(pro),仍空则不返回, + # 落到外循环切下一个 key(2026-07-22 实测:空输出会"假成功"阻断轮换)── + if not result.strip(): + if model_name != FALLBACK_MODEL and ch_name.startswith("ocg"): + print(f" [LLM] {ch_name} {model_name} 空输出({elapsed:.1f}s)," + f"升级 {FALLBACK_MODEL} 重试...", flush=True) + esc_payload = json.dumps({ + "model": FALLBACK_MODEL, "messages": messages, + "max_tokens": max_tokens, + }).encode() + try: + ok2, result2 = _post(ch_url, ch_headers, esc_payload, timeout) + total_attempts += 1 + if ok2 and result2.strip(): + print(f" [LLM] 升级 {FALLBACK_MODEL} 成功, 输出{len(result2)}字", flush=True) + return { + "ok": True, "content": result2, "error": None, + "model": FALLBACK_MODEL, + "elapsed": time.monotonic() - t_start, + "attempts": total_attempts, "channel": ch_name + "+esc", + } + print(f" [LLM] {ch_name} 升级 {FALLBACK_MODEL} 仍空", flush=True) + except Exception as e2: + print(f" [LLM] 升级 {FALLBACK_MODEL} 异常: {str(e2)[:100]}", flush=True) + # 仍空 → 不 return,作为本通道失败处理,外循环切下一个 key + last_err = "empty content" + print(f" [LLM] {ch_name} 空输出视为失败,切换下一 key...", flush=True) + continue print(f" [LLM] {ch_name} 尝试{attempt+1}/{retries+1} 成功, " f"{elapsed:.1f}s, 输出{len(result)}字, model={model_name}", flush=True) return {