From ff39dbcfa9ff94ecfee6d60623794aae96fe3ef0 Mon Sep 17 00:00:00 2001 From: xxm Date: Mon, 17 Aug 2026 11:47:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20llm=5Fclient=E6=8C=89OCG-Router=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E2=80=94=E2=80=94max=5Ftokens=E9=BB=98=E8=AE=A4None?= =?UTF-8?q?=E4=B8=8D=E5=86=99=E5=85=A5payload(=E6=8E=A8=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=83=A7=E5=85=89=E6=A0=B9=E5=9B=A0),timeout150?= =?UTF-8?q?=E2=86=92180?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/llm_client.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/deploy/profile-scripts/llm_client.py b/deploy/profile-scripts/llm_client.py index 686bcd24..ca468f87 100644 --- a/deploy/profile-scripts/llm_client.py +++ b/deploy/profile-scripts/llm_client.py @@ -215,8 +215,13 @@ def gateway_alive(timeout=5): return False -def call_llm(prompt, model=None, max_tokens=4096, timeout=150, +def call_llm(prompt, model=None, max_tokens=None, timeout=180, retries=1, backoff=20, system=None, concurrent=False): + # 2026-08-17 OCG-Router文档对齐: + # max_tokens 默认 None=不写入 payload(deepseek-v4-flash 是推理模型,指定 max_tokens + # 会被 reasoning tokens 烧光 → finish=length 空输出。不指定用模型默认 1M 上下文)。 + # timeout 150→180(文档普通请求建议)。 + # retries/backoff 保持 1/20:6 通道链下多重试=疯狂重试(文档禁止项),20s 退避防限流。 """调用 LLM:OCG 直连优先,hermes gateway 兜底。带重试和结构化日志。 Args: @@ -235,18 +240,18 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150, 永远不抛异常到调用方。 """ model_name = model or REASSESS_MODEL - # OCG/deepseek 对过小 max_tokens 会短路返回空(2026-07-22 实测 max_tokens=64 必空) - if max_tokens < 512: + # 仅显式传入时才钳制下限(防过小短路,2026-07-22 实测 max_tokens=64 必空); + # None = 不指定(遵循文档:推理模型不设上限) + if max_tokens is not None and max_tokens < 512: max_tokens = 512 messages = [] if system: messages.append({"role": "system", "content": system}) messages.append({"role": "user", "content": prompt}) - payload = json.dumps({ - "model": model_name, - "messages": messages, - "max_tokens": max_tokens, - }).encode() + _req = {"model": model_name, "messages": messages} + if max_tokens is not None: + _req["max_tokens"] = max_tokens + payload = json.dumps(_req).encode() # ── 构建通道列表:SenseNova(快,同款model) → OCG路由代理(本地,自动选key) → key池直连 → gateway 兜底 ── # 2026-08-13 老莫修复 ocg_router bug 后,路由代理作为 OCG 主通道(自动选最空闲key+故障冷却)。