From 9f1db8b55c193e301f6047136fcc780c09318d83 Mon Sep 17 00:00:00 2001 From: xxm Date: Thu, 13 Aug 2026 00:59:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20LLM=E9=87=8D=E8=AF=84=E6=8E=A5=E5=85=A5?= =?UTF-8?q?OCG=E8=B7=AF=E7=94=B1=E4=BB=A3=E7=90=86(:19878)=E4=B8=BB?= =?UTF-8?q?=E9=80=9A=E9=81=93=E2=80=94=E2=80=94=E8=80=81=E8=8E=AB=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Drouter=20bug=E5=90=8E=E9=85=8D=E7=BD=AE,=E9=80=9A?= =?UTF-8?q?=E9=81=93=E9=A1=BA=E5=BA=8Focg=5Frouter=E2=86=92sensenova?= =?UTF-8?q?=E2=86=92key=E6=B1=A0=E2=86=92gateway,=E6=94=AF=E6=8C=81pro?= =?UTF-8?q?=E5=8D=87=E7=BA=A7+=E5=A4=9Akey=E8=87=AA=E5=8A=A8=E9=80=89key+?= =?UTF-8?q?=E5=B9=B6=E5=8F=9116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/llm_client.py | 37 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/deploy/profile-scripts/llm_client.py b/deploy/profile-scripts/llm_client.py index 77b683f0..f86c932b 100644 --- a/deploy/profile-scripts/llm_client.py +++ b/deploy/profile-scripts/llm_client.py @@ -32,6 +32,10 @@ FALLBACK_MODEL = "deepseek-v4-pro" # 主通道:OCG 上游直连(与 hermes providers.ocg-key6 同源) # key 运行时从 hermes config 读取(SSOT,不落盘到代码库) OCG_URL = "https://opencode.ai/zen/go/v1/chat/completions" +# 本地 OCG 路由代理(2026-08-13 老莫修复bug后启用):池化多key自动选最空闲+故障冷却 +# 与 hermes ocg-router provider 同源,MoFin 重评主通道 +OCG_ROUTER = "http://127.0.0.1:19878/v1/chat/completions" +OCG_ROUTER_AUTH = "Bearer ocg-router-local" _HERMES_CONFIG = "/home/hmo/.hermes/profiles/position-analyst/config.yaml" @@ -176,15 +180,24 @@ def _post(url, headers, payload, timeout): def ocg_alive(timeout=8): - """OCG 上游可达性快检(极小请求)。key 缺失直接 False。""" + """OCG 可达性快检(极小请求)。优先本地路由代理,回退直连。""" + payload = json.dumps({ + "model": REASSESS_MODEL, + "messages": [{"role": "user", "content": "ping"}], + "max_tokens": 1, + }).encode() + # 本地路由代理 + try: + _post(OCG_ROUTER, {"Content-Type": "application/json", + "Authorization": OCG_ROUTER_AUTH, + "User-Agent": "curl/8.5.0"}, payload, timeout) + return True + except Exception: + pass + # 直连兜底 if not OCG_HEADERS: return False try: - payload = json.dumps({ - "model": REASSESS_MODEL, - "messages": [{"role": "user", "content": "ping"}], - "max_tokens": 1, - }).encode() _post(OCG_URL, OCG_HEADERS, payload, timeout) return True except Exception: @@ -233,9 +246,17 @@ def call_llm(prompt, model=None, max_tokens=4096, timeout=150, "max_tokens": max_tokens, }).encode() - # ── 构建通道列表:SenseNova(快,同款model) → key池(OCG直连) → gateway 兜底 ── - # 2026-07-24:OCG开盘高峰45s+/call且空输出高发,SenseNova托管同款deepseek-v4-flash实测3.2s + # ── 构建通道列表:SenseNova(快,同款model) → OCG路由代理(本地,自动选key) → key池直连 → gateway 兜底 ── + # 2026-08-13 老莫修复 ocg_router bug 后,路由代理作为 OCG 主通道(自动选最空闲key+故障冷却)。 + # key池直连保留为 fallback(router 不可达时回退)。 channels = [] + # OCG 路由代理第一(2026-08-13 老莫:重评配置到 OCG 路由代理,支持pro升级+多key池) + channels.append(("ocg_router", OCG_ROUTER, { + "Content-Type": "application/json", + "Authorization": OCG_ROUTER_AUTH, + "User-Agent": "curl/8.5.0", + })) + # SenseNova 快通道(并发应急,不支持 pro 升级) if SN_HEADERS: channels.append(("sensenova", SN_URL, SN_HEADERS)) pool = _get_key_pool()