From 11bef44901ca8711044195911f1aaea48d9505e1 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sun, 13 Jul 2025 20:45:21 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=BF=80?= =?UTF-8?q?=E6=B4=BB=E5=92=8C=E6=94=B9=E5=86=99=E7=9A=84=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E9=99=90=E5=88=B6=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=89=AAplanner=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/focus_chat/heartFC_chat.py | 2 +- src/chat/memory_system/Hippocampus.py | 2 +- src/chat/memory_system/memory_activator.py | 2 +- src/chat/planner_actions/action_modifier.py | 2 +- src/chat/planner_actions/planner.py | 2 +- src/chat/replyer/default_generator.py | 4 +- src/plugins/built_in/core_actions/plugin.py | 54 +++++++++++---------- 7 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index e31bcf126..577af5d00 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -585,7 +585,7 @@ class HeartFChatting: reply_to=reply_to, available_actions=available_actions, enable_tool=global_config.tool.enable_in_normal_chat, - request_type="normal.replyer", + request_type="chat.replyer.normal", ) if not success or not reply_set: diff --git a/src/chat/memory_system/Hippocampus.py b/src/chat/memory_system/Hippocampus.py index b999379ac..3956ae305 100644 --- a/src/chat/memory_system/Hippocampus.py +++ b/src/chat/memory_system/Hippocampus.py @@ -199,7 +199,7 @@ class Hippocampus: # 从数据库加载记忆图 self.entorhinal_cortex.sync_memory_from_db() # TODO: API-Adapter修改标记 - self.model_summary = LLMRequest(global_config.model.memory, request_type="memory") + self.model_summary = LLMRequest(global_config.model.memory, request_type="memory.builder") def get_all_node_names(self) -> list: """获取记忆图中所有节点的名字列表""" diff --git a/src/chat/memory_system/memory_activator.py b/src/chat/memory_system/memory_activator.py index 66ff89755..715d9c067 100644 --- a/src/chat/memory_system/memory_activator.py +++ b/src/chat/memory_system/memory_activator.py @@ -66,7 +66,7 @@ class MemoryActivator: self.key_words_model = LLMRequest( model=global_config.model.utils_small, temperature=0.5, - request_type="memory_activator", + request_type="memory.activator", ) self.running_memory = [] diff --git a/src/chat/planner_actions/action_modifier.py b/src/chat/planner_actions/action_modifier.py index e051d1a38..ba9fcbdc3 100644 --- a/src/chat/planner_actions/action_modifier.py +++ b/src/chat/planner_actions/action_modifier.py @@ -71,7 +71,7 @@ class ActionModifier: message_list_before_now_half = get_raw_msg_before_timestamp_with_chat( chat_id=self.chat_stream.stream_id, timestamp=time.time(), - limit=int(global_config.chat.max_context_size * 0.5), + limit=min(int(global_config.chat.max_context_size * 0.33), 10), ) chat_content = build_readable_messages( message_list_before_now_half, diff --git a/src/chat/planner_actions/planner.py b/src/chat/planner_actions/planner.py index 6cbaaa434..f1eaf6ac1 100644 --- a/src/chat/planner_actions/planner.py +++ b/src/chat/planner_actions/planner.py @@ -224,7 +224,7 @@ class ActionPlanner: message_list_before_now = get_raw_msg_before_timestamp_with_chat( chat_id=self.chat_id, timestamp=time.time(), - limit=global_config.chat.max_context_size, + limit=int(global_config.chat.max_context_size * 0.6), ) chat_content_block = build_readable_messages( diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index a26b76875..0b6e23aca 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -280,7 +280,7 @@ class DefaultReplyer: # 加权随机选择一个模型配置 selected_model_config = self._select_weighted_model_config() logger.info( - f"{self.log_prefix} 使用模型配置进行重写: {selected_model_config.get('model_name', 'N/A')} (权重: {selected_model_config.get('weight', 1.0)})" + f"{self.log_prefix} 使用模型配置进行重写: {selected_model_config.get('name', 'N/A')} (权重: {selected_model_config.get('weight', 1.0)})" ) express_model = LLMRequest( @@ -797,7 +797,7 @@ class DefaultReplyer: message_list_before_now_half = get_raw_msg_before_timestamp_with_chat( chat_id=chat_id, timestamp=time.time(), - limit=int(global_config.chat.max_context_size * 0.5), + limit=min(int(global_config.chat.max_context_size * 0.33), 15), ) chat_talking_prompt_half = build_readable_messages( message_list_before_now_half, diff --git a/src/plugins/built_in/core_actions/plugin.py b/src/plugins/built_in/core_actions/plugin.py index ad81c63fd..a3c46f6cf 100644 --- a/src/plugins/built_in/core_actions/plugin.py +++ b/src/plugins/built_in/core_actions/plugin.py @@ -75,34 +75,38 @@ class ReplyAction(BaseAction): reply_to = self.action_data.get("reply_to", "") sender, target = self._parse_reply_target(reply_to) - + try: - try: - success, reply_set, _ = await asyncio.wait_for( - generator_api.generate_reply( - action_data=self.action_data, - chat_id=self.chat_id, - request_type="focus.replyer", - enable_tool=global_config.tool.enable_in_focus_chat, - ), - timeout=global_config.chat.thinking_timeout, + prepared_reply = self.action_data.get("prepared_reply", "") + if not prepared_reply: + try: + success, reply_set, _ = await asyncio.wait_for( + generator_api.generate_reply( + action_data=self.action_data, + chat_id=self.chat_id, + request_type="chat.replyer.focus", + enable_tool=global_config.tool.enable_in_focus_chat, + ), + timeout=global_config.chat.thinking_timeout, + ) + except asyncio.TimeoutError: + logger.warning(f"{self.log_prefix} 回复生成超时 ({global_config.chat.thinking_timeout}s)") + return False, "timeout" + + # 检查从start_time以来的新消息数量 + # 获取动作触发时间或使用默认值 + current_time = time.time() + new_message_count = message_api.count_new_messages( + chat_id=self.chat_id, start_time=start_time, end_time=current_time ) - except asyncio.TimeoutError: - logger.warning(f"{self.log_prefix} 回复生成超时 ({global_config.chat.thinking_timeout}s)") - return False, "timeout" - # 检查从start_time以来的新消息数量 - # 获取动作触发时间或使用默认值 - current_time = time.time() - new_message_count = message_api.count_new_messages( - chat_id=self.chat_id, start_time=start_time, end_time=current_time - ) - - # 根据新消息数量决定是否使用reply_to - need_reply = new_message_count >= random.randint(2, 4) - logger.info( - f"{self.log_prefix} 从思考到回复,共有{new_message_count}条新消息,{'使用' if need_reply else '不使用'}引用回复" - ) + # 根据新消息数量决定是否使用reply_to + need_reply = new_message_count >= random.randint(2, 4) + logger.info( + f"{self.log_prefix} 从思考到回复,共有{new_message_count}条新消息,{'使用' if need_reply else '不使用'}引用回复" + ) + else: + reply_text = prepared_reply # 构建回复文本 reply_text = ""