From 919bcd4e2e7c1c197e8b22b80a6dbfa2de12386d Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Wed, 29 Oct 2025 10:05:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86=E6=8F=90=E7=A4=BA=E8=AF=8D=E4=B8=8E?= =?UTF-8?q?=E5=85=B4=E8=B6=A3=E5=BA=A6=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在默认回复器中移除未读消息的兴趣度显示,简化回复逻辑 - 在亲和流聊天器的计划过滤器中保留兴趣度显示,供planner决策使用 - 更新planner提示词,明确兴趣度优先原则但禁止在思考流中使用技术术语 - 统一历史消息区块的标题描述,提高可读性 --- src/chat/replyer/default_generator.py | 37 +++++-------------- .../affinity_flow_chatter/plan_filter.py | 13 ++++--- .../affinity_flow_chatter/planner_prompts.py | 8 ++-- 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index caf4b50ce..6578fd215 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -92,12 +92,12 @@ def init_prompt(): - {schedule_block} ## 历史记录 -### 📜 已读历史消息(仅供参考) +### 📜 已读历史消息 {read_history_prompt} {cross_context_block} -### 📬 未读历史消息(动作执行对象) +### 📬 未读历史消息 {unread_history_prompt} {notice_block} @@ -129,13 +129,10 @@ def init_prompt(): ### 核心任务 - 你现在的主要任务是和 {sender_name} 聊天。同时,也有其他用户会参与聊天,你可以参考他们的回复内容,但是你现在想回复{sender_name}的发言。 -- {reply_target_block} 你需要生成一段紧密相关的回复。 +- {reply_target_block} 你需要生成一段紧密相关且与历史消息相关的回复。 ## 规则 {safety_guidelines_block} -**重要提醒:** -- **已读历史消息仅作为当前聊天情景的参考** -- **未读历史消息是你需要回应的对象** 你的回复应该是一条简短、完整且口语化的回复。 @@ -986,14 +983,9 @@ class DefaultReplyer: else: read_history_prompt = "暂无已读历史消息" - # 构建未读历史消息 prompt(包含兴趣度) + # 构建未读历史消息 prompt unread_history_prompt = "" if unread_messages: - # 尝试获取兴趣度评分 - interest_scores = await self._get_interest_scores_for_messages( - [msg.flatten() for msg in unread_messages] - ) - unread_lines = [] for msg in unread_messages: msg_id = msg.message_id @@ -1029,14 +1021,11 @@ class DefaultReplyer: replace_bot_name=True ) - # 添加兴趣度信息 - interest_score = interest_scores.get(msg_id, 0.0) - interest_text = f" [兴趣度: {interest_score:.3f}]" if interest_score > 0 else "" - - unread_lines.append(f"{msg_time} {sender_name}: {msg_content}{interest_text}") + # 不显示兴趣度,replyer只需要关注消息内容本身 + unread_lines.append(f"{msg_time} {sender_name}: {msg_content}") unread_history_prompt_str = "\n".join(unread_lines) - unread_history_prompt = f"这是未读历史消息,包含兴趣度评分,请优先对兴趣值高的消息做出动作:\n{unread_history_prompt_str}" + unread_history_prompt = f"这是未读历史消息:\n{unread_history_prompt_str}" else: unread_history_prompt = "暂无未读历史消息" @@ -1098,9 +1087,6 @@ class DefaultReplyer: # 构建未读历史消息 prompt unread_history_prompt = "" if unread_messages: - # 尝试获取兴趣度评分 - interest_scores = await self._get_interest_scores_for_messages(unread_messages) - unread_lines = [] for msg in unread_messages: msg_id = msg.get("message_id", "") @@ -1135,15 +1121,12 @@ class DefaultReplyer: replace_bot_name=True ) - # 添加兴趣度信息 - interest_score = interest_scores.get(msg_id, 0.0) - interest_text = f" [兴趣度: {interest_score:.3f}]" if interest_score > 0 else "" - - unread_lines.append(f"{msg_time} {sender_name}: {msg_content}{interest_text}") + # 不显示兴趣度,replyer只需要关注消息内容本身 + unread_lines.append(f"{msg_time} {sender_name}: {msg_content}") unread_history_prompt_str = "\n".join(unread_lines) unread_history_prompt = ( - f"这是未读历史消息,包含兴趣度评分,请优先对兴趣值高的消息做出动作:\n{unread_history_prompt_str}" + f"这是未读历史消息:\n{unread_history_prompt_str}" ) else: unread_history_prompt = "暂无未读历史消息" diff --git a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py index b51e13145..3005b4e40 100644 --- a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py +++ b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py @@ -310,7 +310,7 @@ class ChatterPlanFilter: flattened_unread = [msg.flatten() for msg in unread_messages] # 尝试获取兴趣度评分(返回以真实 message_id 为键的字典) - await self._get_interest_scores_for_messages(flattened_unread) + interest_scores = await self._get_interest_scores_for_messages(flattened_unread) # 为未读消息分配短 id(保持与 build_readable_messages_with_id 的一致结构) message_id_list = assign_message_ids(flattened_unread) @@ -319,14 +319,17 @@ class ChatterPlanFilter: for idx, msg in enumerate(flattened_unread): mapped = message_id_list[idx] synthetic_id = mapped.get("id") - msg.get("message_id") or msg.get("id") + real_msg_id = msg.get("message_id") or msg.get("id") msg_time = time.strftime("%H:%M:%S", time.localtime(msg.get("time", time.time()))) user_nickname = msg.get("user_nickname", "未知用户") msg_content = msg.get("processed_plain_text", "") - # 不再显示兴趣度,但保留合成ID供模型内部使用 - # 同时,为了让模型更好地理解上下文,我们显示用户名 - unread_lines.append(f"<{synthetic_id}> {msg_time} {user_nickname}: {msg_content}") + # 获取兴趣度信息并显示在提示词中 + interest_score = interest_scores.get(real_msg_id, 0.0) + interest_text = f" [兴趣度: {interest_score:.3f}]" if interest_score > 0 else "" + + # 在未读消息中显示兴趣度,让planner优先选择兴趣度高的消息 + unread_lines.append(f"<{synthetic_id}> {msg_time} {user_nickname}: {msg_content}{interest_text}") unread_history_block = "\n".join(unread_lines) else: diff --git a/src/plugins/built_in/affinity_flow_chatter/planner_prompts.py b/src/plugins/built_in/affinity_flow_chatter/planner_prompts.py index f4aa696c9..6f2bcc6f3 100644 --- a/src/plugins/built_in/affinity_flow_chatter/planner_prompts.py +++ b/src/plugins/built_in/affinity_flow_chatter/planner_prompts.py @@ -46,8 +46,10 @@ def init_prompts(): # 决策流程 1. 已读仅供参考,不能对已读执行任何动作。 2. 目标消息必须来自未读历史,并使用其前缀 作为 target_message_id。 -3. 优先级: +3. **【重要】兴趣度优先原则**:每条未读消息后都标注了 [兴趣度: X.XXX],数值越高表示该消息越值得你关注和回复。在选择回复目标时,**应优先选择兴趣度高的消息**(通常 ≥0.5 表示较高兴趣),除非有特殊情况(如被直接@或提问)。 +4. 优先级: - 直接针对你:@你、回复你、点名提问、引用你的消息。 + - **兴趣度高的消息**:兴趣度 ≥0.5 的消息应优先考虑回复。 - 与你强相关的话题或你熟悉的问题。 - 其他与上下文弱相关的内容最后考虑。 {mentioned_bonus} @@ -58,9 +60,9 @@ def init_prompts(): # 思绪流规范(thinking) - 真实、自然、非结论化,像给自己看的随笔。 -- 描述你看到/想到/感觉到的过程,不要出现“因此/我决定”等总结词。 +- 描述你看到/想到/感觉到的过程,不要出现"因此/我决定"等总结词。 - 直接使用对方昵称,而不是 / 这样的标签。 -- 禁止出现“兴趣度、分数”等技术术语或内部实现细节。 +- **禁止出现"兴趣度、分数"等技术术语或内部实现细节**。兴趣度仅用于你内部的决策权重,不要在thinking中提及,而应该用自然语言描述你对消息的感受(如"这个话题挺有意思的"、"我对这个很感兴趣"等)。 ## 可用动作列表 {action_options_text}