feat(llm): flash空输出自动升级pro重试(688617实测flash三连空/pro正常输出)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user