From 22dca15f0a78a7e340a6252c490b35a647013f7f Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sun, 16 Nov 2025 00:16:23 +0800 Subject: [PATCH] =?UTF-8?q?planner=E6=80=9D=E8=80=83=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E5=8A=A0=E5=85=A5replyer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/heart_flow/heartFC_chat.py | 6 ++++-- src/chat/replyer/group_generator.py | 7 +++++++ src/chat/replyer/private_generator.py | 7 +++++++ src/chat/replyer/prompt/replyer_prompt.py | 4 +++- src/common/database/database_model.py | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/chat/heart_flow/heartFC_chat.py b/src/chat/heart_flow/heartFC_chat.py index bd99d2a7..a7d37e77 100644 --- a/src/chat/heart_flow/heartFC_chat.py +++ b/src/chat/heart_flow/heartFC_chat.py @@ -764,7 +764,9 @@ class HeartFChatting: # 重置连续 no_reply 计数 self.consecutive_no_reply_count = 0 - reason = action_planner_info.reasoning or "选择回复" + reason = action_planner_info.reasoning or "" + # 使用 action_reasoning(planner 的整体思考理由)作为 reply_reason + planner_reasoning = action_planner_info.action_reasoning or reason await database_api.store_action_info( chat_stream=self.chat_stream, action_build_into_prompt=False, @@ -781,7 +783,7 @@ class HeartFChatting: reply_message=action_planner_info.action_message, available_actions=available_actions, chosen_actions=chosen_action_plan_infos, - reply_reason=reason, + reply_reason=planner_reasoning, enable_tool=global_config.tool.enable_tool, request_type="replyer", from_plugin=False, diff --git a/src/chat/replyer/group_generator.py b/src/chat/replyer/group_generator.py index b26ba548..e2eb9085 100644 --- a/src/chat/replyer/group_generator.py +++ b/src/chat/replyer/group_generator.py @@ -845,6 +845,12 @@ class DefaultReplyer: keywords_reaction_prompt = await self.build_keywords_reaction_prompt(target) mood_state_prompt: str = results_dict["mood_state_prompt"] + # 从 chosen_actions 中提取 planner 的整体思考理由 + planner_reasoning = "" + if reply_reason: + # 如果没有 chosen_actions,使用 reply_reason 作为备选 + planner_reasoning = f"你的想法是:{reply_reason}" + if extra_info: extra_info_block = f"以下是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策\n{extra_info}\n以上是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策" else: @@ -899,6 +905,7 @@ class DefaultReplyer: moderation_prompt=moderation_prompt_block, memory_retrieval=memory_retrieval, chat_prompt=chat_prompt_block, + planner_reasoning=planner_reasoning, ), selected_expressions async def build_prompt_rewrite_context( diff --git a/src/chat/replyer/private_generator.py b/src/chat/replyer/private_generator.py index 37019724..5f194048 100644 --- a/src/chat/replyer/private_generator.py +++ b/src/chat/replyer/private_generator.py @@ -765,6 +765,12 @@ class PrivateReplyer: memory_retrieval: str = results_dict["memory_retrieval"] keywords_reaction_prompt = await self.build_keywords_reaction_prompt(target) + # 从 chosen_actions 中提取 planner 的整体思考理由 + planner_reasoning = "" + if reply_reason: + # 如果没有 chosen_actions,使用 reply_reason 作为备选 + planner_reasoning = f"你的想法是:{reply_reason}" + if extra_info: extra_info_block = f"以下是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策\n{extra_info}\n以上是你在回复时需要参考的信息,现在请你阅读以下内容,进行决策" else: @@ -834,6 +840,7 @@ class PrivateReplyer: sender_name=sender, memory_retrieval=memory_retrieval, chat_prompt=chat_prompt_block, + planner_reasoning=planner_reasoning, ), selected_expressions async def build_prompt_rewrite_context( diff --git a/src/chat/replyer/prompt/replyer_prompt.py b/src/chat/replyer/prompt/replyer_prompt.py index 5fe98b7a..7c7a91e3 100644 --- a/src/chat/replyer/prompt/replyer_prompt.py +++ b/src/chat/replyer/prompt/replyer_prompt.py @@ -16,12 +16,13 @@ def init_replyer_prompt(): {dialogue_prompt} {reply_target_block}。 +{planner_reasoning} {identity} {chat_prompt}你正在群里聊天,现在请你读读之前的聊天记录,然后给出日常且口语化的回复,平淡一些,{mood_state} 尽量简短一些。{keywords_reaction_prompt}请注意把握聊天内容,不要回复的太有条理,可以有个性。 {reply_style} 请注意不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只输出一句回复内容就好。 -不要输出多余内容(包括前后缀,冒号和引号,括号,表情包,at或 @等 )。请不要思考太长 +不要输出多余内容(包括前后缀,冒号和引号,括号,表情包,at或 @等 )。 现在,你说:""", "replyer_prompt", ) @@ -35,6 +36,7 @@ def init_replyer_prompt(): {dialogue_prompt} {reply_target_block}。 +{planner_reasoning} {identity} {chat_prompt}你正在和{sender_name}聊天,现在请你读读之前的聊天记录,然后给出日常且口语化的回复,平淡一些,{mood_state} 尽量简短一些。{keywords_reaction_prompt}请注意把握聊天内容,不要回复的太有条理,可以有个性。 diff --git a/src/common/database/database_model.py b/src/common/database/database_model.py index 873738ce..3673e6d2 100644 --- a/src/common/database/database_model.py +++ b/src/common/database/database_model.py @@ -335,6 +335,8 @@ class Jargon(BaseModel): is_jargon = BooleanField(null=True) # None表示未判定,True表示是黑话,False表示不是黑话 last_inference_count = IntegerField(null=True) # 最后一次判定的count值,用于避免重启后重复判定 is_complete = BooleanField(default=False) # 是否已完成所有推断(count>=100后不再推断) + inference_with_context = TextField(null=True) # 基于上下文的推断结果(JSON格式) + inference_content_only = TextField(null=True) # 仅基于词条的推断结果(JSON格式) class Meta: table_name = "jargon"