From 4411859e375e9d58b316e8875d6c1bda6462fd6f Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sat, 26 Jul 2025 11:01:55 +0800 Subject: [PATCH] =?UTF-8?q?better=EF=BC=9A=E4=BC=98=E5=8C=96focus=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=92=8Cno=5Freply=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/chat_loop/heartFC_chat.py | 25 ++++++++----------- src/chat/willing/mode_classical.py | 2 +- src/config/official_configs.py | 8 ++---- src/plugins/built_in/core_actions/no_reply.py | 18 ++++++------- template/bot_config_template.toml | 7 +++--- 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/chat/chat_loop/heartFC_chat.py b/src/chat/chat_loop/heartFC_chat.py index ac8c7d2df..085ef2d2a 100644 --- a/src/chat/chat_loop/heartFC_chat.py +++ b/src/chat/chat_loop/heartFC_chat.py @@ -88,11 +88,6 @@ class HeartFChatting: self.loop_mode = ChatMode.NORMAL # 初始循环模式为普通模式 - # 新增:消息计数器和疲惫阈值 - self._message_count = 0 # 发送的消息计数 - self._message_threshold = max(10, int(30 * global_config.chat.focus_value)) - self._fatigue_triggered = False # 是否已触发疲惫退出 - self.action_manager = ActionManager() self.action_planner = ActionPlanner(chat_id=self.stream_id, action_manager=self.action_manager) self.action_modifier = ActionModifier(action_manager=self.action_manager, chat_id=self.stream_id) @@ -112,7 +107,6 @@ class HeartFChatting: self.last_read_time = time.time() - 1 - self.willing_amplifier = 1 self.willing_manager = get_willing_manager() logger.info(f"{self.log_prefix} HeartFChatting 初始化完成") @@ -182,6 +176,9 @@ class HeartFChatting: if self.loop_mode == ChatMode.NORMAL: self.energy_value -= 0.3 self.energy_value = max(self.energy_value, 0.3) + if self.loop_mode == ChatMode.FOCUS: + self.energy_value -= 0.6 + self.energy_value = max(self.energy_value, 0.3) def print_cycle_info(self, cycle_timers): # 记录循环信息和计时器结果 @@ -200,9 +197,9 @@ class HeartFChatting: async def _loopbody(self): if self.loop_mode == ChatMode.FOCUS: if await self._observe(): - self.energy_value -= 1 * global_config.chat.focus_value + self.energy_value -= 1 / global_config.chat.focus_value else: - self.energy_value -= 3 * global_config.chat.focus_value + self.energy_value -= 3 / global_config.chat.focus_value if self.energy_value <= 1: self.energy_value = 1 self.loop_mode = ChatMode.NORMAL @@ -219,12 +216,12 @@ class HeartFChatting: filter_bot=True, ) - if len(new_messages_data) > 3 * global_config.chat.focus_value: + if len(new_messages_data) > 3 / pow(global_config.chat.focus_value,0.5): self.loop_mode = ChatMode.FOCUS - self.energy_value = 10 + (len(new_messages_data) / (3 * global_config.chat.focus_value)) * 10 + self.energy_value = 10 + (len(new_messages_data) / (3 / pow(global_config.chat.focus_value,0.5))) * 10 return True - if self.energy_value >= 30 * global_config.chat.focus_value: + if self.energy_value >= 30: self.loop_mode = ChatMode.FOCUS return True @@ -235,10 +232,10 @@ class HeartFChatting: if_think = await self.normal_response(earliest_messages_data) if if_think: factor = max(global_config.chat.focus_value, 0.1) - self.energy_value *= 1.1 / factor + self.energy_value *= 1.1 * factor logger.info(f"{self.log_prefix} 进行了思考,能量值按倍数增加,当前能量值:{self.energy_value:.1f}") else: - self.energy_value += 0.1 / global_config.chat.focus_value + self.energy_value += 0.1 * global_config.chat.focus_value logger.debug(f"{self.log_prefix} 没有进行思考,能量值线性增加,当前能量值:{self.energy_value:.1f}") logger.debug(f"{self.log_prefix} 当前能量值:{self.energy_value:.1f}") @@ -501,7 +498,7 @@ class HeartFChatting: 在"兴趣"模式下,判断是否回复并生成内容。 """ - interested_rate = (message_data.get("interest_value") or 0.0) * self.willing_amplifier + interested_rate = (message_data.get("interest_value") or 0.0) * global_config.chat.willing_amplifier self.willing_manager.setup(message_data, self.chat_stream) diff --git a/src/chat/willing/mode_classical.py b/src/chat/willing/mode_classical.py index 57400c44d..dc159aa1e 100644 --- a/src/chat/willing/mode_classical.py +++ b/src/chat/willing/mode_classical.py @@ -28,7 +28,7 @@ class ClassicalWillingManager(BaseWillingManager): # print(f"[{chat_id}] 回复意愿: {current_willing}") - interested_rate = willing_info.interested_rate * global_config.normal_chat.response_interested_rate_amplifier + interested_rate = willing_info.interested_rate # print(f"[{chat_id}] 兴趣值: {interested_rate}") diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 82284d9b3..73310f769 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -68,6 +68,8 @@ class ChatConfig(ConfigBase): max_context_size: int = 18 """上下文长度""" + + willing_amplifier: float = 1.0 replyer_random_probability: float = 0.5 """ @@ -273,12 +275,6 @@ class NormalChatConfig(ConfigBase): willing_mode: str = "classical" """意愿模式""" - response_interested_rate_amplifier: float = 1.0 - """回复兴趣度放大系数""" - - - - @dataclass class ExpressionConfig(ConfigBase): """表达配置类""" diff --git a/src/plugins/built_in/core_actions/no_reply.py b/src/plugins/built_in/core_actions/no_reply.py index e9fad9107..bfa66dac8 100644 --- a/src/plugins/built_in/core_actions/no_reply.py +++ b/src/plugins/built_in/core_actions/no_reply.py @@ -39,14 +39,14 @@ class NoReplyAction(BaseAction): # 新增:兴趣值退出阈值 _interest_exit_threshold = 3.0 # 新增:消息数量退出阈值 - _min_exit_message_count = 5 - _max_exit_message_count = 10 + _min_exit_message_count = 3 + _max_exit_message_count = 6 # 动作参数定义 action_parameters = {} # 动作使用场景 - action_require = ["你发送了消息,目前无人回复"] + action_require = [""] # 关联类型 associated_types = [] @@ -66,9 +66,6 @@ class NoReplyAction(BaseAction): # 随机生成本次等待需要的新消息数量阈值 exit_message_count_threshold = random.randint(self._min_exit_message_count, self._max_exit_message_count) - logger.info( - f"{self.log_prefix} 本次no_reply需要 {exit_message_count_threshold} 条新消息或累计兴趣值超过 {self._interest_exit_threshold} 才能打断" - ) logger.info(f"{self.log_prefix} 选择不回复(第{count}次),开始摸鱼,原因: {reason}") @@ -89,9 +86,12 @@ class NoReplyAction(BaseAction): # 2. 检查消息数量是否达到阈值 talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id) - if new_message_count >= exit_message_count_threshold / talk_frequency: + + modified_exit_count_threshold = (exit_message_count_threshold / talk_frequency) / global_config.chat.willing_amplifier + + if new_message_count >= modified_exit_count_threshold: logger.info( - f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{exit_message_count_threshold / talk_frequency}),结束等待" + f"{self.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold}),结束等待" ) exit_reason = f"{global_config.bot.nickname}(你)看到了{new_message_count}条新消息,可以考虑一下是否要进行回复" await self.store_action_info( @@ -108,7 +108,7 @@ class NoReplyAction(BaseAction): text = msg_dict.get("processed_plain_text", "") interest_value = msg_dict.get("interest_value", 0.0) if text: - accumulated_interest += interest_value + accumulated_interest += interest_value * global_config.chat.willing_amplifier talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id) # 只在兴趣值变化时输出log diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index ff8a79e73..e8ca5e5b4 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "4.4.8" +version = "4.4.9" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #如果你想要修改配置文件,请在修改后将version的值进行变更 @@ -52,9 +52,11 @@ relation_frequency = 1 # 关系频率,麦麦构建关系的频率 [chat] #麦麦的聊天通用设置 focus_value = 1 -# 麦麦的专注思考能力,越低越容易专注,消耗token也越多 +# 麦麦的专注思考能力,越高越容易专注,可能消耗更多token # 专注时能更好把握发言时机,能够进行持久的连续对话 +willing_amplifier = 1 # 麦麦回复意愿 + max_context_size = 25 # 上下文长度 thinking_timeout = 20 # 麦麦一次回复最长思考规划时间,超过这个时间的思考会放弃(往往是api反应太慢) replyer_random_probability = 0.5 # 首要replyer模型被选择的概率 @@ -105,7 +107,6 @@ ban_msgs_regex = [ [normal_chat] #普通聊天 willing_mode = "classical" # 回复意愿模式 —— 经典模式:classical,mxp模式:mxp,自定义模式:custom(需要你自己实现) -response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数 [tool] enable_in_normal_chat = false # 是否在普通聊天中启用工具