fix: stabilize auth sync and stream recovery for ji
This commit is contained in:
1 parent
5bf08c83a6
commit
68c4896088
6 files changed
+118
-50
No files matched your search
+15
-15
@@ -33,14 +33,14 @@ logger = logging.getLogger(__name__)
|
||||
LLM_ERROR_MARKER = "deerflow_llm_error"
|
||||
|
||||
# 各 reason 对应的用户可见兜底文案(单一数据源:构造与识别都用它)。
|
||||
_USER_MESSAGES: dict[str, str] = {
|
||||
"quota": "大模型因账户额度不足、账单异常或使用受限而拒绝请求,请检查模型账户后再试。",
|
||||
"auth": "大模型因鉴权失败或无访问权限而拒绝请求,请检查模型的 API Key 与权限配置后再试。",
|
||||
"busy": "大模型因服务繁忙或网络异常,多次重试后仍未恢复,请稍候再继续。",
|
||||
"transient": "大模型因服务繁忙或网络异常,多次重试后仍未恢复,请稍候再继续。",
|
||||
"upstream": "大模型当前响应异常(上游模型或网关临时故障),多次重试后仍未恢复,请稍后再试或更换模型。",
|
||||
"generic": "大模型本次调用未能成功完成,请稍后再试或更换模型。",
|
||||
}
|
||||
_USER_MESSAGES: dict[str, str] = {
|
||||
"quota": "大模型因账户额度不足、账单异常或使用受限而拒绝请求,请检查模型账户后再试。",
|
||||
"auth": "大模型因鉴权失败或无访问权限而拒绝请求,请检查模型的 API Key 与权限配置后再试。",
|
||||
"busy": "大模型服务暂时繁忙,多次自动重试后仍未恢复,请稍候再继续。",
|
||||
"transient": "大模型响应暂时中断或超时,多次自动重试后仍未恢复,请稍候再继续。",
|
||||
"upstream": "大模型当前响应异常(上游模型或网关临时故障),多次重试后仍未恢复,请稍后再试或更换模型。",
|
||||
"generic": "大模型本次调用未能成功完成,请稍后再试或更换模型。",
|
||||
}
|
||||
_CIRCUIT_MESSAGE = "大模型因连续多次调用失败已被熔断保护,请稍候再试。"
|
||||
# 全部兜底文案集合,供 ``is_llm_error_message`` 在 additional_kwargs 被剥离时按正文回退识别。
|
||||
_ALL_ERROR_MESSAGES: frozenset[str] = frozenset({*_USER_MESSAGES.values(), _CIRCUIT_MESSAGE})
|
||||
@@ -249,13 +249,13 @@ class LLMErrorHandlingMiddleware(AgentMiddleware[AgentState]):
|
||||
|
||||
def _build_retry_message(self, attempt: int, wait_ms: int, reason: str) -> str:
|
||||
seconds = max(1, round(wait_ms / 1000))
|
||||
if reason == "busy":
|
||||
reason_text = "服务繁忙"
|
||||
elif reason == "upstream":
|
||||
reason_text = "上游响应异常"
|
||||
else:
|
||||
reason_text = "网络/连接异常"
|
||||
return f"大模型因{reason_text}调用失败,正在第 {attempt}/{self.retry_max_attempts} 次重试,{seconds} 秒后继续…"
|
||||
if reason == "busy":
|
||||
reason_text = "服务繁忙"
|
||||
elif reason == "upstream":
|
||||
reason_text = "上游响应异常"
|
||||
else:
|
||||
reason_text = "响应中断或超时"
|
||||
return f"大模型因{reason_text}暂未返回,正在第 {attempt}/{self.retry_max_attempts} 次自动重试,{seconds} 秒后继续…"
|
||||
|
||||
def _build_circuit_breaker_message(self) -> str:
|
||||
return _CIRCUIT_MESSAGE
|
||||
|
||||
Reference in new issue
Block a user