fix: LLM 客户端自建大超时 Client,绕开 SDK 默认 60s unary 超时
CURSOR_MODEL=auto 时后端首 token 常超过 SDK 默认 unary_timeout, 自建带 DAILY_CURSOR_UNARY_TIMEOUT(300s)/DAILY_CURSOR_STREAM_TIMEOUT(900s) 的 Client 并显式传入 Agent.prompt,finally 中关闭释放资源。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,7 @@ def _cursor_chat(system: str, user: str) -> str:
|
||||
api_key = (env("CURSOR_API_KEY") or "").strip()
|
||||
if not api_key:
|
||||
return ""
|
||||
from cursor_sdk import Agent, AgentOptions, CursorAgentError, LocalAgentOptions
|
||||
from cursor_sdk import Agent, AgentOptions, Client, CursorAgentError, LocalAgentOptions
|
||||
|
||||
from daily.bridge_manager import warm_cursor_bridge
|
||||
|
||||
@@ -83,6 +83,17 @@ def _cursor_chat(system: str, user: str) -> str:
|
||||
warm_cursor_bridge()
|
||||
model = env("CURSOR_MODEL") or "composer-2.5"
|
||||
prompt = f"{system}\n\n{user}"
|
||||
|
||||
# SDK 默认 unary_timeout 只有 60s,CURSOR_MODEL=auto 时后端首 token 常超时;
|
||||
# 自建带大超时的 Client 绕开 _default_client(),unary/stream 都放大。
|
||||
unary_timeout = env_int("DAILY_CURSOR_UNARY_TIMEOUT", 300)
|
||||
stream_timeout = env_int("DAILY_CURSOR_STREAM_TIMEOUT", 900)
|
||||
client = Client(
|
||||
base_url=os.environ["CURSOR_SDK_BRIDGE_URL"],
|
||||
auth_token=os.environ["CURSOR_SDK_BRIDGE_TOKEN"],
|
||||
unary_timeout=unary_timeout,
|
||||
stream_timeout=stream_timeout,
|
||||
)
|
||||
try:
|
||||
result = Agent.prompt(
|
||||
prompt,
|
||||
@@ -91,9 +102,12 @@ def _cursor_chat(system: str, user: str) -> str:
|
||||
model=model,
|
||||
local=LocalAgentOptions(cwd=cwd),
|
||||
),
|
||||
client=client,
|
||||
)
|
||||
except CursorAgentError as exc:
|
||||
raise RuntimeError(f"LLM 调用失败:{exc.message}") from exc
|
||||
finally:
|
||||
client.close()
|
||||
if result.status == "error":
|
||||
raise RuntimeError(f"LLM 调用失败:{result.result or '未知错误'}")
|
||||
return (result.result or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user