diff --git a/src/chat/memory_system/memory_activator.py b/src/chat/memory_system/memory_activator.py index 8640f2a88..104d0c88f 100644 --- a/src/chat/memory_system/memory_activator.py +++ b/src/chat/memory_system/memory_activator.py @@ -111,7 +111,6 @@ class MemoryActivator: # 添加新的关键词到缓存 self.cached_keywords.update(keywords) - # 调用记忆系统获取相关记忆 related_memory = await hippocampus_manager.get_memory_from_topic( diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index a1f1e1bdf..07b4f2908 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -28,6 +28,7 @@ willing_manager = get_willing_manager() logger = get_logger("normal_chat") + class NormalChat: """ 普通聊天处理类,负责处理非核心对话的聊天逻辑。 @@ -61,7 +62,7 @@ class NormalChat: self.willing_amplifier = 1 self.start_time = time.time() - + self.mood_manager = mood_manager self.start_time = time.time() @@ -77,7 +78,6 @@ class NormalChat: self.recent_replies = [] self.max_replies_history = 20 # 最多保存最近20条回复记录 - # 添加回调函数,用于在满足条件时通知切换到focus_chat模式 self.on_switch_to_focus_callback = on_switch_to_focus_callback @@ -561,16 +561,14 @@ class NormalChat: async def reply_one_message(self, message: MessageRecv) -> None: # 回复前处理 await self.relationship_builder.build_relation() - + thinking_id = await self._create_thinking_message(message) # 如果启用planner,预先修改可用actions(避免在并行任务中重复调用) available_actions = None if self.enable_planner: try: - await self.action_modifier.modify_actions( - mode="normal", message_content=message.processed_plain_text - ) + await self.action_modifier.modify_actions(mode="normal", message_content=message.processed_plain_text) available_actions = self.action_manager.get_using_actions_for_mode("normal") except Exception as e: logger.warning(f"[{self.stream_name}] 获取available_actions失败: {e}") @@ -647,7 +645,7 @@ class NormalChat: logger.info(f"[{self.stream_name}] 回复内容中没有文本,不发送消息") await self._cleanup_thinking_message_by_id(thinking_id) return False - + # 发送回复 (不再需要传入 chat) first_bot_msg = await self._add_messages_to_manager(message, reply_texts, thinking_id) @@ -954,6 +952,7 @@ class NormalChat: except Exception as e: logger.warning(f"[{self.stream_name}] 获取疲劳调整系数时出错: {e}") return 1.0 # 出错时返回正常系数 + async def _check_should_switch_to_focus(self) -> bool: """ 检查是否满足切换到focus模式的条件 @@ -1027,4 +1026,4 @@ def get_recent_message_stats(minutes: int = 30, chat_id: str = None) -> dict: bot_filter["user_id"] = bot_id bot_reply_count = count_messages(bot_filter) - return {"bot_reply_count": bot_reply_count, "total_message_count": total_message_count} \ No newline at end of file + return {"bot_reply_count": bot_reply_count, "total_message_count": total_message_count} diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index befa22230..51f62ba96 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -98,7 +98,6 @@ class DefaultReplyer: self.log_prefix = "replyer" self.request_type = request_type - if model_configs: self.express_model_configs = model_configs else: @@ -470,7 +469,13 @@ class DefaultReplyer: duration = end_time - start_time return name, result, duration - async def build_prompt_reply_context(self, reply_data=None, available_actions: List[str] = None, enable_timeout: bool = False, enable_tool: bool = True) -> str: + async def build_prompt_reply_context( + self, + reply_data=None, + available_actions: List[str] = None, + enable_timeout: bool = False, + enable_tool: bool = True, + ) -> str: """ 构建回复器上下文 @@ -537,10 +542,16 @@ class DefaultReplyer: # 并行执行四个构建任务 task_results = await asyncio.gather( - self._time_and_run_task(self.build_expression_habits(chat_talking_prompt_half, target), "build_expression_habits"), - self._time_and_run_task(self.build_relation_info(reply_data, chat_talking_prompt_half), "build_relation_info"), + self._time_and_run_task( + self.build_expression_habits(chat_talking_prompt_half, target), "build_expression_habits" + ), + self._time_and_run_task( + self.build_relation_info(reply_data, chat_talking_prompt_half), "build_relation_info" + ), self._time_and_run_task(self.build_memory_block(chat_talking_prompt_half, target), "build_memory_block"), - self._time_and_run_task(self.build_tool_info(reply_data, chat_talking_prompt_half, enable_tool=enable_tool), "build_tool_info"), + self._time_and_run_task( + self.build_tool_info(reply_data, chat_talking_prompt_half, enable_tool=enable_tool), "build_tool_info" + ), ) # 处理结果 diff --git a/src/config/official_configs.py b/src/config/official_configs.py index e8ecb2885..a18f4a99b 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -273,7 +273,6 @@ class MessageReceiveConfig(ConfigBase): class NormalChatConfig(ConfigBase): """普通聊天配置类""" - willing_mode: str = "classical" """意愿模式""" @@ -290,7 +289,6 @@ class NormalChatConfig(ConfigBase): """是否启用动作规划器""" - @dataclass class FocusChatConfig(ConfigBase): """专注聊天配置类""" @@ -340,7 +338,7 @@ class ToolConfig(ConfigBase): @dataclass class EmojiConfig(ConfigBase): """表情包配置类""" - + emoji_chance: float = 0.6 """发送表情包的基础概率""" diff --git a/src/person_info/relationship_fetcher.py b/src/person_info/relationship_fetcher.py index e2bde69de..f1c62851a 100644 --- a/src/person_info/relationship_fetcher.py +++ b/src/person_info/relationship_fetcher.py @@ -106,7 +106,7 @@ class RelationshipFetcher: await self._extract_single_info(person_id, info_type, person_name) relation_info = self._organize_known_info() - if short_impression and relation_info: + if short_impression and relation_info: relation_info = f"你对{person_name}的印象是:{short_impression}。具体来说:{relation_info}" elif short_impression: relation_info = f"你对{person_name}的印象是:{short_impression}" diff --git a/src/plugin_system/apis/generator_api.py b/src/plugin_system/apis/generator_api.py index ead002064..d4ed0f51b 100644 --- a/src/plugin_system/apis/generator_api.py +++ b/src/plugin_system/apis/generator_api.py @@ -92,9 +92,7 @@ async def generate_reply( """ try: # 获取回复器 - replyer = get_replyer( - chat_stream, chat_id, model_configs=model_configs, request_type=request_type - ) + replyer = get_replyer(chat_stream, chat_id, model_configs=model_configs, request_type=request_type) if not replyer: logger.error("[GeneratorAPI] 无法获取回复器") return False, [] diff --git a/src/tools/tool_executor.py b/src/tools/tool_executor.py index b43dfcff3..b7b0d8f69 100644 --- a/src/tools/tool_executor.py +++ b/src/tools/tool_executor.py @@ -45,7 +45,7 @@ class ToolExecutor: self.chat_id = chat_id self.chat_stream = get_chat_manager().get_stream(self.chat_id) self.log_prefix = f"[{get_chat_manager().get_stream_name(self.chat_id) or self.chat_id}]" - + self.llm_model = LLMRequest( model=global_config.model.tool_use, request_type="tool_executor",