feat: llm_client并发模式——call_llm加concurrent参数,OCG router加X-OCG-Mode: concurrent header触发round-robin锁key轮询
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user