From e29e9e563ab53c92b159611183afe0976dacece7 Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Tue, 2 Sep 2025 21:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=EF=BC=9A4b59eda=EF=BC=88feat?= =?UTF-8?q?:=E4=BF=AE=E6=94=B9focus=20value=E7=9A=84=E7=94=A8=E9=80=94?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/chat_loop/cycle_processor.py | 2 +- src/chat/chat_loop/heartFC_chat.py | 47 ++++++++++++--------------- src/chat/chat_loop/hfc_context.py | 2 +- template/bot_config_template.toml | 9 ++--- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/chat/chat_loop/cycle_processor.py b/src/chat/chat_loop/cycle_processor.py index f913ff079..76bea6a16 100644 --- a/src/chat/chat_loop/cycle_processor.py +++ b/src/chat/chat_loop/cycle_processor.py @@ -133,7 +133,7 @@ class CycleProcessor: x0 = 1.0 # 控制曲线中心点 return 1.0 / (1.0 + math.exp(-k * (interest_val - x0))) - normal_mode_probability = calculate_normal_mode_probability(interest_value) + normal_mode_probability = calculate_normal_mode_probability(interest_value) / global_config.chat.get_current_talk_frequency(self.context.stream_id) # 根据概率决定使用哪种模式 if random.random() < normal_mode_probability: diff --git a/src/chat/chat_loop/heartFC_chat.py b/src/chat/chat_loop/heartFC_chat.py index 7d2671b57..895fb4b0d 100644 --- a/src/chat/chat_loop/heartFC_chat.py +++ b/src/chat/chat_loop/heartFC_chat.py @@ -415,49 +415,44 @@ class HeartFChatting: 根据当前循环模式和消息内容决定是否继续处理 """ new_message_count = len(new_message) - talk_frequency = global_config.chat.get_current_talk_frequency(self.context.chat_stream.stream_id) - modified_exit_count_threshold = self.context.focus_energy / talk_frequency + # talk_frequency = global_config.chat.get_current_talk_frequency(self.context.chat_stream.stream_id) + modified_exit_count_threshold = self.context.focus_energy / global_config.chat.focus_value + + total_interest = 0.0 + for msg_dict in new_message: + interest_value = msg_dict.get("interest_value", 0.0) + if msg_dict.get("processed_plain_text", ""): + total_interest += interest_value if new_message_count >= modified_exit_count_threshold: - # 记录兴趣度到列表 - total_interest = 0.0 - for msg_dict in new_message: - interest_value = msg_dict.get("interest_value", 0.0) - if msg_dict.get("processed_plain_text", ""): - total_interest += interest_value - + # 记录兴趣度到列表 self.recent_interest_records.append(total_interest) logger.info( - f"{self.context.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold}),结束等待" + f"{self.context.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold:.1f}),结束等待" ) - logger.info(self.context.last_read_time) - logger.info(new_message) + # logger.info(self.context.last_read_time) + # logger.info(new_message) return True,total_interest/new_message_count # 检查累计兴趣值 if new_message_count > 0: - accumulated_interest = 0.0 - for msg_dict in new_message: - text = msg_dict.get("processed_plain_text", "") - interest_value = msg_dict.get("interest_value", 0.0) - if text: - accumulated_interest += interest_value # 只在兴趣值变化时输出log - if not hasattr(self, "_last_accumulated_interest") or accumulated_interest != self._last_accumulated_interest: - logger.info(f"{self.context.log_prefix} breaking形式当前累计兴趣值: {accumulated_interest:.2f}, 当前聊天频率: {talk_frequency:.2f}") - self._last_accumulated_interest = accumulated_interest - if accumulated_interest >= 3 / talk_frequency: + if not hasattr(self, "_last_accumulated_interest") or total_interest != self._last_accumulated_interest: + logger.info(f"{self.context.log_prefix} breaking形式当前累计兴趣值: {total_interest:.2f}, 专注度: {global_config.chat.focus_value:.1f}") + self._last_accumulated_interest = total_interest + if total_interest >= 3 / global_config.chat.focus_value: # 记录兴趣度到列表 - self.recent_interest_records.append(accumulated_interest) + self.recent_interest_records.append(total_interest) logger.info( - f"{self.context.log_prefix} 累计兴趣值达到{accumulated_interest:.2f}(>{5 / talk_frequency}),结束等待" + f"{self.context.log_prefix} 累计兴趣值达到{total_interest:.2f}(>{3 / global_config.chat.focus_value}),结束等待" ) - return True,accumulated_interest/new_message_count + return True,total_interest/new_message_count + # 每10秒输出一次等待状态 if int(time.time() - self.context.last_read_time) > 0 and int(time.time() - self.context.last_read_time) % 10 == 0: logger.info( - f"{self.context.log_prefix} 已等待{time.time() - self.context.last_read_time:.0f}秒,累计{new_message_count}条消息,继续等待..." + f"{self.context.log_prefix} 已等待{time.time() - self.last_read_time:.0f}秒,累计{new_message_count}条消息,累计兴趣{total_interest:.1f},继续等待..." ) await asyncio.sleep(0.5) diff --git a/src/chat/chat_loop/hfc_context.py b/src/chat/chat_loop/hfc_context.py index ca99dd467..a4cf2a313 100644 --- a/src/chat/chat_loop/hfc_context.py +++ b/src/chat/chat_loop/hfc_context.py @@ -62,7 +62,7 @@ class HfcContext: self.focus_energy = 1 self.no_reply_consecutive = 0 - + self.total_interest = 0.0 # 引用HeartFChatting实例,以便其他组件可以调用其方法 self.chat_instance = None diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 6a5f8baa8..196ff5ff7 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "6.6.0" +version = "6.7.0" #----以下是给开发人员阅读的,如果你只是部署了MoFox-Bot,不需要阅读---- #如果你想要修改配置文件,请递增version的值 @@ -104,11 +104,12 @@ learning_strength = 0.5 [chat] #MoFox-Bot的聊天通用设置 # 群聊聊天模式设置 group_chat_mode = "auto" # 群聊聊天模式:auto-自动切换,normal-强制普通模式,focus-强制专注模式 -focus_value = 1 -# MoFox-Bot的专注思考能力,越高越容易专注,可能消耗更多token,仅限自动切换模式下使用哦 +talk_frequency = 1 +# MoFox-Bot活跃度,越高,麦麦回复越多 # 专注时能更好把握发言时机,能够进行持久的连续对话 -talk_frequency = 1 # MoFox-Bot活跃度,越高,MoFox-Bot回复越频繁,仅限normal/或者自动切换的normal模式下使用哦 +focus_value = 1 +# MoFox-Bot的专注思考能力,越高越容易持续连续对话 # 强制私聊专注模式 force_focus_private = false # 是否强制私聊进入专注模式,开启后私聊将始终保持专注状态