fix: 空输出不再假成功——升级pro仍空时落到外循环切下一个key
This commit is contained in:
@@ -224,29 +224,34 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150,
|
|||||||
ok, result = _post(ch_url, ch_headers, payload, timeout)
|
ok, result = _post(ch_url, ch_headers, payload, timeout)
|
||||||
elapsed = time.monotonic() - t0
|
elapsed = time.monotonic() - t0
|
||||||
if ok:
|
if ok:
|
||||||
# ── 空输出升级:flash 对部分 prompt 稳定返回空(688617 实测),
|
# ── 空输出视为失败:先同 key 升 FALLBACK_MODEL(pro),仍空则不返回,
|
||||||
# 先同 key 换 FALLBACK_MODEL(pro) 重试;仍空则让外循环切下一个 key ──
|
# 落到外循环切下一个 key(2026-07-22 实测:空输出会"假成功"阻断轮换)──
|
||||||
if not result.strip() and model_name != FALLBACK_MODEL and ch_name.startswith("ocg"):
|
if not result.strip():
|
||||||
print(f" [LLM] {ch_name} {model_name} 空输出({elapsed:.1f}s),"
|
if model_name != FALLBACK_MODEL and ch_name.startswith("ocg"):
|
||||||
f"升级 {FALLBACK_MODEL} 重试...", flush=True)
|
print(f" [LLM] {ch_name} {model_name} 空输出({elapsed:.1f}s),"
|
||||||
esc_payload = json.dumps({
|
f"升级 {FALLBACK_MODEL} 重试...", flush=True)
|
||||||
"model": FALLBACK_MODEL, "messages": messages,
|
esc_payload = json.dumps({
|
||||||
"max_tokens": max_tokens,
|
"model": FALLBACK_MODEL, "messages": messages,
|
||||||
}).encode()
|
"max_tokens": max_tokens,
|
||||||
try:
|
}).encode()
|
||||||
ok2, result2 = _post(ch_url, ch_headers, esc_payload, timeout)
|
try:
|
||||||
total_attempts += 1
|
ok2, result2 = _post(ch_url, ch_headers, esc_payload, timeout)
|
||||||
if ok2 and result2.strip():
|
total_attempts += 1
|
||||||
print(f" [LLM] 升级 {FALLBACK_MODEL} 成功, 输出{len(result2)}字", flush=True)
|
if ok2 and result2.strip():
|
||||||
return {
|
print(f" [LLM] 升级 {FALLBACK_MODEL} 成功, 输出{len(result2)}字", flush=True)
|
||||||
"ok": True, "content": result2, "error": None,
|
return {
|
||||||
"model": FALLBACK_MODEL,
|
"ok": True, "content": result2, "error": None,
|
||||||
"elapsed": time.monotonic() - t_start,
|
"model": FALLBACK_MODEL,
|
||||||
"attempts": total_attempts, "channel": ch_name + "+esc",
|
"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] {ch_name} 升级 {FALLBACK_MODEL} 仍空", flush=True)
|
||||||
print(f" [LLM] 升级 {FALLBACK_MODEL} 异常: {str(e2)[:100]}", 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} 成功, "
|
print(f" [LLM] {ch_name} 尝试{attempt+1}/{retries+1} 成功, "
|
||||||
f"{elapsed:.1f}s, 输出{len(result)}字, model={model_name}", flush=True)
|
f"{elapsed:.1f}s, 输出{len(result)}字, model={model_name}", flush=True)
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user