From 0477cf0c717826cd3de7ebf74d0dd1c972112bb4 Mon Sep 17 00:00:00 2001 From: hmo Date: Fri, 14 Aug 2026 04:36:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20llm=5Fclient=E5=B9=B6=E5=8F=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E2=80=94=E2=80=94call=5Fllm=E5=8A=A0concurrent?= =?UTF-8?q?=E5=8F=82=E6=95=B0,OCG=20router=E5=8A=A0X-OCG-Mode:=20concurren?= =?UTF-8?q?t=20header=E8=A7=A6=E5=8F=91round-robin=E9=94=81key=E8=BD=AE?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/llm_client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/deploy/profile-scripts/llm_client.py b/deploy/profile-scripts/llm_client.py index f86c932b..85fb3495 100644 --- a/deploy/profile-scripts/llm_client.py +++ b/deploy/profile-scripts/llm_client.py @@ -216,7 +216,7 @@ def gateway_alive(timeout=5): def call_llm(prompt, model=None, max_tokens=4096, timeout=150, - retries=1, backoff=20, system=None): + retries=1, backoff=20, system=None, concurrent=False): """调用 LLM:OCG 直连优先,hermes gateway 兜底。带重试和结构化日志。 Args: @@ -227,6 +227,8 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150, retries: 每个通道的失败重试次数 backoff: 重试间隔(秒) system: 可选 system message + concurrent: 并发模式(2026-08-13):True 时 OCG router 用 round-robin 锁 key 轮询, + 避免并发压同一 key(header X-OCG-Mode: concurrent) Returns: {ok, content, error, model, elapsed, attempts, channel} @@ -251,11 +253,15 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150, # key池直连保留为 fallback(router 不可达时回退)。 channels = [] # OCG 路由代理第一(2026-08-13 老莫:重评配置到 OCG 路由代理,支持pro升级+多key池) - channels.append(("ocg_router", OCG_ROUTER, { + _ocg_headers = { "Content-Type": "application/json", "Authorization": OCG_ROUTER_AUTH, "User-Agent": "curl/8.5.0", - })) + } + # 2026-08-13 并发模式:concurrent=True 时加 header,ocg_router round-robin 锁 key 轮询 + if concurrent: + _ocg_headers["X-OCG-Mode"] = "concurrent" + channels.append(("ocg_router", OCG_ROUTER, _ocg_headers)) # SenseNova 快通道(并发应急,不支持 pro 升级) if SN_HEADERS: channels.append(("sensenova", SN_URL, SN_HEADERS))