From 7718a9b95610f6a3a55f141c5f3ea98910a3ac85 Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Fri, 26 Sep 2025 14:02:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(chat):=20=E4=BB=8EStreamContext?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=B6=88=E6=81=AF=E5=85=B4=E8=B6=A3=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E8=BF=9E=E7=BB=AD=E6=97=A0=E5=9B=9E=E5=A4=8D=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/message_manager/message_manager.py | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/chat/message_manager/message_manager.py b/src/chat/message_manager/message_manager.py index 25053d39a..427f50207 100644 --- a/src/chat/message_manager/message_manager.py +++ b/src/chat/message_manager/message_manager.py @@ -321,9 +321,14 @@ class MessageManager: if chat_stream: focus_energy = chat_stream.focus_energy - # 获取平均消息兴趣度用于更精确的计算 - if chat_stream.message_count > 0: - avg_message_interest = chat_stream.message_interest_total / chat_stream.message_count + # 获取平均消息兴趣度用于更精确的计算 - 从StreamContext获取 + history_messages = context.get_history_messages(limit=100) + unread_messages = context.get_unread_messages() + all_messages = history_messages + unread_messages + + if all_messages: + message_interests = [msg.interest_degree for msg in all_messages if hasattr(msg, 'interest_degree')] + avg_message_interest = sum(message_interests) / len(message_interests) if message_interests else 0.5 # 获取AFC阈值用于参考,添加None值检查 reply_threshold = getattr(global_config.affinity_flow, 'reply_action_interest_threshold', 0.4) @@ -542,9 +547,17 @@ class MessageManager: time_since_active = current_time - context.last_check_time time_penalty = max(0, 1.0 - time_since_active / 3600.0) # 1小时内无惩罚 - # 连续无回复惩罚 + # 连续无回复惩罚 - 从StreamContext历史消息计算 if chat_stream: - consecutive_no_reply = chat_stream.consecutive_no_reply + # 计算连续无回复次数 + consecutive_no_reply = 0 + all_messages = context.get_history_messages(limit=50) + context.get_unread_messages() + for msg in reversed(all_messages): + if hasattr(msg, 'should_reply') and msg.should_reply: + if not (hasattr(msg, 'actions') and 'reply' in (msg.actions or [])): + consecutive_no_reply += 1 + else: + break no_reply_penalty = max(0, 1.0 - consecutive_no_reply * 0.05) # 每次无回复降低5% else: no_reply_penalty = 1.0