From f50a28bb350092304c3420524e41156c39cfcdc8 Mon Sep 17 00:00:00 2001 From: zk Date: Thu, 9 Jul 2026 10:58:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E9=97=B4=E9=9A=94=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/ai_tool.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/services/ai_tool.py b/app/services/ai_tool.py index 14f07db..9c6a68d 100644 --- a/app/services/ai_tool.py +++ b/app/services/ai_tool.py @@ -82,11 +82,10 @@ async def ai_chat(llm: BaseChatModel, system_prompt: str, user_message: str, sce async def _probe_until_recover(llm: BaseChatModel, system_prompt: str, user_message: str) -> str: - """探针:退避重试直到接口恢复,返回成功的响应内容,并打开门闸唤醒所有等待协程""" + """探针:固定间隔重试直到接口恢复,返回成功的响应内容,并打开门闸唤醒所有等待协程""" global _gate_probing - delay = 1.0 # 初始退避 1 秒 - max_delay = 30.0 # 最大退避 30 秒 + delay = 0.5 # 固定间隔 500ms attempt = 0 while True: @@ -104,8 +103,7 @@ async def _probe_until_recover(llm: BaseChatModel, system_prompt: str, user_mess log.info("AI 接口恢复,门闸打开,第{}次探测成功", attempt) return response.content except Exception as e: - log.warning("AI 接口仍不可用,第{}次探测失败(退避{}s): {}", attempt, delay, e) - delay = min(delay * 2, max_delay) + log.warning("AI 接口仍不可用,第{}次探测失败(间隔{}ms): {}", attempt, int(delay * 1000), e) async def ai_chat_json(llm: BaseChatModel, system_prompt: str, user_message: str, scene: Optional[str] = None) -> Any: