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: