From c2c3c062b77bb384e521b5934880995ba38e219e Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Wed, 10 Dec 2025 11:34:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(interest=5Fcalculator):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=85=B4=E8=B6=A3=E8=AE=A1=E7=AE=97=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=EF=BC=8C=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/interest_system/interest_manager.py | 7 +++++-- .../core/affinity_interest_calculator.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/chat/interest_system/interest_manager.py b/src/chat/interest_system/interest_manager.py index c58cfea76..10e43aee4 100644 --- a/src/chat/interest_system/interest_manager.py +++ b/src/chat/interest_system/interest_manager.py @@ -91,12 +91,12 @@ class InterestManager: logger.error(f"注册兴趣值计算组件失败: {e}") return False - async def calculate_interest(self, message: "DatabaseMessages", timeout: float = 2.0) -> InterestCalculationResult: + async def calculate_interest(self, message: "DatabaseMessages", timeout: float | None = None) -> InterestCalculationResult: """计算消息兴趣值 Args: message: 数据库消息对象 - timeout: 最大等待时间(秒),超时则使用默认值返回 + timeout: 最大等待时间(秒),超时则使用默认值返回;为None时不设置超时 Returns: InterestCalculationResult: 计算结果或默认结果 @@ -113,6 +113,9 @@ class InterestManager: # 使用 create_task 异步执行计算 task = asyncio.create_task(self._async_calculate(message)) + if timeout is None: + return await task + try: # 等待计算结果,但有超时限制 result = await asyncio.wait_for(task, timeout=timeout) diff --git a/src/plugins/built_in/affinity_flow_chatter/core/affinity_interest_calculator.py b/src/plugins/built_in/affinity_flow_chatter/core/affinity_interest_calculator.py index a70ede231..ef254625e 100644 --- a/src/plugins/built_in/affinity_flow_chatter/core/affinity_interest_calculator.py +++ b/src/plugins/built_in/affinity_flow_chatter/core/affinity_interest_calculator.py @@ -191,12 +191,12 @@ class AffinityInterestCalculator(BaseInterestCalculator): logger.debug(f"开始兴趣匹配计算,内容: {content[:50]}...") try: - # 使用机器人的兴趣标签系统进行智能匹配(1.5秒超时保护) + # 使用机器人的兴趣标签系统进行智能匹配(5秒超时保护) match_result = await asyncio.wait_for( bot_interest_manager.calculate_interest_match( content, keywords or [], getattr(message, "semantic_embedding", None) ), - timeout=1.5 + timeout=5.0 ) logger.debug(f"兴趣匹配结果: {match_result}") @@ -215,7 +215,7 @@ class AffinityInterestCalculator(BaseInterestCalculator): return 0.0 except asyncio.TimeoutError: - logger.warning("[超时] 兴趣匹配计算超时(>1.5秒),返回默认分值0.5以保留其他分数") + logger.warning("[超时] 兴趣匹配计算超时(>5秒),返回默认分值0.5以保留其他分数") return 0.5 # 超时时返回默认分值,避免丢失提及分和关系分 except Exception as e: logger.warning(f"智能兴趣匹配失败: {e}")