diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index 9df666831..ae387eb45 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -406,9 +406,7 @@ class HeartFChatting: try: # 使用 await task 来获取结果或触发异常 result_list = await task - logger.info( - f"{self.log_prefix} 处理器 {processor_name} 已完成!" - ) + logger.info(f"{self.log_prefix} 处理器 {processor_name} 已完成!") if result_list is not None: all_plan_info.extend(result_list) else: diff --git a/src/chat/focus_chat/planners/actions/reply_action.py b/src/chat/focus_chat/planners/actions/reply_action.py index 43a31f64a..df3413398 100644 --- a/src/chat/focus_chat/planners/actions/reply_action.py +++ b/src/chat/focus_chat/planners/actions/reply_action.py @@ -101,7 +101,7 @@ class ReplyAction(BaseAction): } """ logger.info(f"{self.log_prefix} 决定回复: {self.reasoning}") - + # 从聊天观察获取锚定消息 chatting_observation: ChattingObservation = next( obs for obs in self.observations if isinstance(obs, ChattingObservation) diff --git a/src/chat/heart_flow/sub_heartflow.py b/src/chat/heart_flow/sub_heartflow.py index d60baa79e..03667d823 100644 --- a/src/chat/heart_flow/sub_heartflow.py +++ b/src/chat/heart_flow/sub_heartflow.py @@ -277,7 +277,7 @@ class SubHeartflow: self.history_chat_state.append((current_state, self.chat_state_last_time)) # logger.info( - # f"{log_prefix} 麦麦的聊天状态从 {current_state.value} (持续了 {int(self.chat_state_last_time)} 秒) 变更为 {new_state.value}" + # f"{log_prefix} 麦麦的聊天状态从 {current_state.value} (持续了 {int(self.chat_state_last_time)} 秒) 变更为 {new_state.value}" # ) self.chat_state.chat_status = new_state diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index fba63aa48..eecc81c2c 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -41,7 +41,6 @@ class NormalChat: self.willing_amplifier = 1 self.start_time = time.time() - # Other sync initializations self.gpt = NormalChatGenerator() self.mood_manager = mood_manager @@ -58,8 +57,6 @@ class NormalChat: self._disabled = False # 增加停用标志 - - async def initialize(self): """异步初始化,获取聊天类型和目标信息。""" if self._initialized: @@ -213,10 +210,9 @@ class NormalChat: try: # 处理消息 if time.time() - self.start_time > 600: - self.adjust_reply_frequency(duration=600/60) + self.adjust_reply_frequency(duration=600 / 60) else: - self.adjust_reply_frequency(duration=(time.time() - self.start_time)/60) - + self.adjust_reply_frequency(duration=(time.time() - self.start_time) / 60) await self.normal_response( message=message, @@ -491,32 +487,38 @@ class NormalChat: 调整回复频率 """ # 获取最近30分钟内的消息统计 - + stats = get_recent_message_stats(minutes=duration, chat_id=self.stream_id) bot_reply_count = stats["bot_reply_count"] total_message_count = stats["total_message_count"] if total_message_count == 0: return - logger.debug(f"[{self.stream_name}]({self.willing_amplifier}) 最近{duration}分钟 回复数量: {bot_reply_count},消息总数: {total_message_count}") + logger.debug( + f"[{self.stream_name}]({self.willing_amplifier}) 最近{duration}分钟 回复数量: {bot_reply_count},消息总数: {total_message_count}" + ) # 计算回复频率 _reply_frequency = bot_reply_count / total_message_count - + differ = global_config.normal_chat.talk_frequency - (bot_reply_count / duration) - + # 如果回复频率低于0.5,增加回复概率 if differ > 0.1: mapped = 1 + (differ - 0.1) * 4 / 0.9 mapped = max(1, min(5, mapped)) - logger.info(f"[{self.stream_name}] 回复频率低于{global_config.normal_chat.talk_frequency},增加回复概率,differ={differ:.3f},映射值={mapped:.2f}") + logger.info( + f"[{self.stream_name}] 回复频率低于{global_config.normal_chat.talk_frequency},增加回复概率,differ={differ:.3f},映射值={mapped:.2f}" + ) self.willing_amplifier += mapped * 0.1 # 你可以根据实际需要调整系数 elif differ < -0.1: mapped = 1 - (differ + 0.1) * 4 / 0.9 mapped = max(1, min(5, mapped)) - logger.info(f"[{self.stream_name}] 回复频率高于{global_config.normal_chat.talk_frequency},减少回复概率,differ={differ:.3f},映射值={mapped:.2f}") + logger.info( + f"[{self.stream_name}] 回复频率高于{global_config.normal_chat.talk_frequency},减少回复概率,differ={differ:.3f},映射值={mapped:.2f}" + ) self.willing_amplifier -= mapped * 0.1 - + if self.willing_amplifier > 5: self.willing_amplifier = 5 elif self.willing_amplifier < 0.1: diff --git a/src/chat/utils/info_catcher.py b/src/chat/utils/info_catcher.py index 27bf2b8cb..a4fb096b9 100644 --- a/src/chat/utils/info_catcher.py +++ b/src/chat/utils/info_catcher.py @@ -111,8 +111,8 @@ class InfoCatcher: result = list(messages_between_query) # print(f"查询结果数量: {len(result)}") # if result: - # print(f"第一条消息时间: {result[0].time}") - # print(f"最后一条消息时间: {result[-1].time}") + # print(f"第一条消息时间: {result[0].time}") + # print(f"最后一条消息时间: {result[-1].time}") return result except Exception as e: print(f"获取消息时出错: {str(e)}") diff --git a/src/common/logger.py b/src/common/logger.py index 049b1b0cb..51d6e6ed1 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -326,7 +326,6 @@ FOCUS_CHAT_STYLE_CONFIG = { } - REMOTE_STYLE_CONFIG = { "advanced": { "console_format": ( @@ -992,6 +991,7 @@ NORMAL_CHAT_STYLE_CONFIG = NORMAL_CHAT_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT e FOCUS_CHAT_STYLE_CONFIG = FOCUS_CHAT_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else FOCUS_CHAT_STYLE_CONFIG["advanced"] EXPRESS_STYLE_CONFIG = EXPRESS_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else EXPRESS_STYLE_CONFIG["advanced"] + def is_registered_module(record: dict) -> bool: """检查是否为已注册的模块""" return record["extra"].get("module") in _handler_registry