From 36214dfa47dd9ac6a01074e701c4375840f2bde6 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Fri, 22 Aug 2025 17:00:42 +0800 Subject: [PATCH] =?UTF-8?q?remove=EF=BC=9A=E7=A7=BB=E9=99=A4sub=5Fhearflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{chat_loop => heart_flow}/heartFC_chat.py | 4 +- src/chat/heart_flow/heartflow.py | 35 +++++++--------- .../heart_flow/heartflow_message_processor.py | 6 +-- .../{chat_loop => heart_flow}/hfc_utils.py | 0 src/chat/heart_flow/sub_heartflow.py | 41 ------------------- template/bot_config_template.toml | 2 +- 6 files changed, 20 insertions(+), 68 deletions(-) rename src/chat/{chat_loop => heart_flow}/heartFC_chat.py (99%) rename src/chat/{chat_loop => heart_flow}/hfc_utils.py (100%) delete mode 100644 src/chat/heart_flow/sub_heartflow.py diff --git a/src/chat/chat_loop/heartFC_chat.py b/src/chat/heart_flow/heartFC_chat.py similarity index 99% rename from src/chat/chat_loop/heartFC_chat.py rename to src/chat/heart_flow/heartFC_chat.py index 7f8c861b..f4200028 100644 --- a/src/chat/chat_loop/heartFC_chat.py +++ b/src/chat/heart_flow/heartFC_chat.py @@ -16,8 +16,8 @@ from src.chat.utils.timer_calculator import Timer from src.chat.planner_actions.planner import ActionPlanner from src.chat.planner_actions.action_modifier import ActionModifier from src.chat.planner_actions.action_manager import ActionManager -from src.chat.chat_loop.hfc_utils import CycleDetail -from src.chat.chat_loop.hfc_utils import send_typing, stop_typing +from src.chat.heart_flow.hfc_utils import CycleDetail +from src.chat.heart_flow.hfc_utils import send_typing, stop_typing from src.chat.memory_system.Hippocampus import hippocampus_manager from src.chat.frequency_control.talk_frequency_control import talk_frequency_control from src.chat.frequency_control.focus_value_control import focus_value_control diff --git a/src/chat/heart_flow/heartflow.py b/src/chat/heart_flow/heartflow.py index 9454b03f..a363a174 100644 --- a/src/chat/heart_flow/heartflow.py +++ b/src/chat/heart_flow/heartflow.py @@ -2,36 +2,29 @@ import traceback from typing import Any, Optional, Dict from src.common.logger import get_logger -from src.chat.heart_flow.sub_heartflow import SubHeartflow - +from src.chat.heart_flow.heartFC_chat import HeartFChatting logger = get_logger("heartflow") - class Heartflow: """主心流协调器,负责初始化并协调聊天""" def __init__(self): - self.subheartflows: Dict[Any, "SubHeartflow"] = {} - - async def get_or_create_subheartflow(self, subheartflow_id: Any) -> Optional["SubHeartflow"]: - """获取或创建一个新的SubHeartflow实例""" - if subheartflow_id in self.subheartflows: - if subflow := self.subheartflows.get(subheartflow_id): - return subflow - + self.heartflow_chat_list: Dict[Any, HeartFChatting] = {} + + async def get_or_create_heartflow_chat(self, chat_id: Any) -> Optional[HeartFChatting]: + """获取或创建一个新的HeartFChatting实例""" try: - new_subflow = SubHeartflow(subheartflow_id) - - await new_subflow.initialize() - - # 注册子心流 - self.subheartflows[subheartflow_id] = new_subflow - - return new_subflow + if chat_id in self.heartflow_chat_list: + if chat := self.heartflow_chat_list.get(chat_id): + return chat + + new_chat = HeartFChatting(chat_id = chat_id) + await new_chat.start() + self.heartflow_chat_list[chat_id] = new_chat + return new_chat except Exception as e: - logger.error(f"创建子心流 {subheartflow_id} 失败: {e}", exc_info=True) + logger.error(f"创建心流聊天 {chat_id} 失败: {e}", exc_info=True) traceback.print_exc() return None - heartflow = Heartflow() diff --git a/src/chat/heart_flow/heartflow_message_processor.py b/src/chat/heart_flow/heartflow_message_processor.py index 8227306f..1db8714e 100644 --- a/src/chat/heart_flow/heartflow_message_processor.py +++ b/src/chat/heart_flow/heartflow_message_processor.py @@ -18,7 +18,7 @@ from src.mood.mood_manager import mood_manager from src.person_info.person_info import Person if TYPE_CHECKING: - from src.chat.heart_flow.sub_heartflow import SubHeartflow + from src.chat.heart_flow.heartFC_chat import HeartFChatting logger = get_logger("chat") @@ -116,11 +116,11 @@ class HeartFCMessageReceiver: await self.storage.store_message(message, chat) - subheartflow: SubHeartflow = await heartflow.get_or_create_subheartflow(chat.stream_id) # type: ignore + heartflow_chat: HeartFChatting = await heartflow.get_or_create_heartflow_chat(chat.stream_id) # type: ignore # subheartflow.add_message_to_normal_chat_cache(message, interested_rate, is_mentioned) if global_config.mood.enable_mood: - chat_mood = mood_manager.get_mood_by_chat_id(subheartflow.chat_id) + chat_mood = mood_manager.get_mood_by_chat_id(heartflow_chat.chat_id) asyncio.create_task(chat_mood.update_mood_by_message(message, interested_rate)) # 3. 日志记录 diff --git a/src/chat/chat_loop/hfc_utils.py b/src/chat/heart_flow/hfc_utils.py similarity index 100% rename from src/chat/chat_loop/hfc_utils.py rename to src/chat/heart_flow/hfc_utils.py diff --git a/src/chat/heart_flow/sub_heartflow.py b/src/chat/heart_flow/sub_heartflow.py deleted file mode 100644 index 275a25a5..00000000 --- a/src/chat/heart_flow/sub_heartflow.py +++ /dev/null @@ -1,41 +0,0 @@ -from rich.traceback import install - -from src.common.logger import get_logger -from src.chat.message_receive.chat_stream import get_chat_manager -from src.chat.chat_loop.heartFC_chat import HeartFChatting -from src.chat.utils.utils import get_chat_type_and_target_info - -logger = get_logger("sub_heartflow") - -install(extra_lines=3) - - -class SubHeartflow: - def __init__( - self, - subheartflow_id, - ): - """子心流初始化函数 - - Args: - subheartflow_id: 子心流唯一标识符 - """ - # 基础属性,两个值是一样的 - self.subheartflow_id = subheartflow_id - self.chat_id = subheartflow_id - - self.is_group_chat, self.chat_target_info = get_chat_type_and_target_info(self.chat_id) - self.log_prefix = get_chat_manager().get_stream_name(self.subheartflow_id) or self.subheartflow_id - - # focus模式退出冷却时间管理 - self.last_focus_exit_time: float = 0 # 上次退出focus模式的时间 - - # 随便水群 normal_chat 和 认真水群 focus_chat 实例 - # CHAT模式激活 随便水群 FOCUS模式激活 认真水群 - self.heart_fc_instance: HeartFChatting = HeartFChatting( - chat_id=self.subheartflow_id, - ) # 该sub_heartflow的HeartFChatting实例 - - async def initialize(self): - """异步初始化方法,创建兴趣流并确定聊天类型""" - await self.heart_fc_instance.start() diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 945d9759..60cb4dd7 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "6.6.0" +version = "6.6.1" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #如果你想要修改配置文件,请递增version的值