From 83b0770db0ad7eaae95bbc14d7799a7752d5cad1 Mon Sep 17 00:00:00 2001 From: hmo Date: Wed, 22 Jul 2026 00:30:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(llm):=20flash=E7=A9=BA=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8D=87=E7=BA=A7pro=E9=87=8D=E8=AF=95?= =?UTF-8?q?=EF=BC=88688617=E5=AE=9E=E6=B5=8Bflash=E4=B8=89=E8=BF=9E?= =?UTF-8?q?=E7=A9=BA/pro=E6=AD=A3=E5=B8=B8=E8=BE=93=E5=87=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/llm_client.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/deploy/profile-scripts/llm_client.py b/deploy/profile-scripts/llm_client.py index 3c14d52b..20e5ea0f 100644 --- a/deploy/profile-scripts/llm_client.py +++ b/deploy/profile-scripts/llm_client.py @@ -25,6 +25,9 @@ import urllib.error # ── 常量:所有重评调用统一使用 ── # 2026-07-21 A/B 实测:flash 与 pro 在新 prompt 下质量差距微弱,flash 快 ~40% REASSESS_MODEL = "deepseek-v4-flash" +# flash 对某些 prompt 会稳定返回空内容(688617 实测三连空),pro 能正常输出。 +# 空输出时自动升级到 pro 重试一次。 +FALLBACK_MODEL = "deepseek-v4-pro" # 主通道:OCG 上游直连(与 hermes providers.ocg-key6 同源) # key 运行时从 hermes config 读取(SSOT,不落盘到代码库) @@ -145,6 +148,29 @@ 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 实测), + # 换 FALLBACK_MODEL(pro) 重试一次 ── + if not result.strip() and model_name != FALLBACK_MODEL and OCG_HEADERS: + 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(OCG_URL, OCG_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] 升级 {FALLBACK_MODEL} 仍空/失败", flush=True) + except Exception as e2: + print(f" [LLM] 升级 {FALLBACK_MODEL} 异常: {str(e2)[:100]}", flush=True) print(f" [LLM] {ch_name} 尝试{attempt+1}/{retries+1} 成功, " f"{elapsed:.1f}s, 输出{len(result)}字, model={model_name}", flush=True) return {