From a2eb4a163bf29cfd8a98e9897cc203f1ed15cc08 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Wed, 28 May 2025 13:58:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E7=A7=81?= =?UTF-8?q?=E8=81=8Abug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/focus_chat/expressors/default_expressor.py | 12 ++++++++---- src/chat/focus_chat/heartFC_chat.py | 2 +- .../focus_chat/info_processors/action_processor.py | 4 ++-- src/chat/normal_chat/normal_chat.py | 4 ++-- src/config/official_configs.py | 10 ++++++---- template/bot_config_template.toml | 5 ++--- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/chat/focus_chat/expressors/default_expressor.py b/src/chat/focus_chat/expressors/default_expressor.py index 4e7bb643f..cbea0a22d 100644 --- a/src/chat/focus_chat/expressors/default_expressor.py +++ b/src/chat/focus_chat/expressors/default_expressor.py @@ -358,14 +358,18 @@ class DefaultExpressor: ) else: # Private chat template_name = "default_expressor_private_prompt" + chat_target_1 = "你正在和人私聊" prompt = await global_prompt_manager.format_prompt( template_name, - sender_name=effective_sender_name, # Used in private template - chat_talking_prompt=chat_talking_prompt, + style_habbits=style_habbits_str, + grammar_habbits=grammar_habbits_str, + chat_target=chat_target_1, + chat_info=chat_talking_prompt, bot_name=global_config.bot.nickname, - prompt_personality=prompt_personality, + prompt_personality="", reason=reason, - moderation_prompt=await global_prompt_manager.get_prompt_async("moderation_prompt"), + in_mind_reply=in_mind_reply, + target_message=target_message, ) return prompt diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index a9ebb1a92..ab061d85b 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -54,7 +54,7 @@ CONSECUTIVE_NO_REPLY_THRESHOLD = 3 # 连续不回复的阈值 logger = get_logger("hfc") # Logger Name Changed # 设定处理器超时时间(秒) -PROCESSOR_TIMEOUT = 10 +PROCESSOR_TIMEOUT = 20 async def _handle_cycle_delay(action_taken_this_cycle: bool, cycle_start_time: float, log_prefix: str): diff --git a/src/chat/focus_chat/info_processors/action_processor.py b/src/chat/focus_chat/info_processors/action_processor.py index dcb8ebd07..f4aa7c1d3 100644 --- a/src/chat/focus_chat/info_processors/action_processor.py +++ b/src/chat/focus_chat/info_processors/action_processor.py @@ -137,9 +137,9 @@ class ActionProcessor(BaseProcessor): # 检查no_reply比例 print(f"no_reply_count: {no_reply_count}, len(recent_cycles): {len(recent_cycles)}") # print(1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111) - if len(recent_cycles) >= (5 * global_config.focus_chat.exit_focus_threshold) and ( + if len(recent_cycles) >= (5 * global_config.chat.exit_focus_threshold) and ( no_reply_count / len(recent_cycles) - ) >= (0.8 * global_config.focus_chat.exit_focus_threshold): + ) >= (0.8 * global_config.chat.exit_focus_threshold): if global_config.chat.chat_mode == "auto": result["add"].append("exit_focus_chat") result["remove"].append("no_reply") diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index bd7ccfaa4..67bc1ab44 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -472,8 +472,8 @@ class NormalChat: return # 如果没有设置回调函数,直接返回 current_time = time.time() - time_threshold = 120 / global_config.focus_chat.auto_focus_threshold - reply_threshold = 6 * global_config.focus_chat.auto_focus_threshold + time_threshold = 120 / global_config.chat.auto_focus_threshold + reply_threshold = 6 * global_config.chat.auto_focus_threshold one_minute_ago = current_time - time_threshold diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 7bb393f6d..5e5199da4 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -59,6 +59,12 @@ class ChatConfig(ConfigBase): chat_mode: str = "normal" """聊天模式""" + + auto_focus_threshold: float = 1.0 + """自动切换到专注聊天的阈值,越低越容易进入专注聊天""" + + exit_focus_threshold: float = 1.0 + """自动退出专注聊天的阈值,越低越容易退出专注聊天""" @dataclass @@ -123,11 +129,7 @@ class NormalChatConfig(ConfigBase): class FocusChatConfig(ConfigBase): """专注聊天配置类""" - auto_focus_threshold: float = 1.0 - """自动切换到专注聊天的阈值,越低越容易进入专注聊天""" - exit_focus_threshold: float = 1.0 - """自动退出专注聊天的阈值,越低越容易退出专注聊天""" observation_context_size: int = 12 """可观察到的最长上下文大小,超过这个值的上下文会被压缩""" diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 31884a93d..c78633408 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -44,6 +44,8 @@ chat_mode = "normal" # 聊天模式 —— 普通模式:normal,专注模式 # chat_mode = "focus" # chat_mode = "auto" +auto_focus_threshold = 1 # 自动切换到专注聊天的阈值,越低越容易进入专注聊天 +exit_focus_threshold = 1 # 自动退出专注聊天的阈值,越低越容易退出专注聊天 # 普通模式下,麦麦会针对感兴趣的消息进行回复,token消耗量较低 # 专注模式下,麦麦会进行主动的观察和回复,并给出回复,token消耗量较高 # 自动模式下,麦麦会根据消息内容自动切换到专注模式或普通模式 @@ -79,9 +81,6 @@ at_bot_inevitable_reply = false # @bot 必然回复 talk_frequency_down_groups = [] #降低回复频率的群号码 [focus_chat] #专注聊天 -auto_focus_threshold = 1 # 自动切换到专注聊天的阈值,越低越容易进入专注聊天 -exit_focus_threshold = 1 # 自动退出专注聊天的阈值,越低越容易退出专注聊天 - think_interval = 3 # 思考间隔 单位秒,可以有效减少消耗 observation_context_size = 15 # 观察到的最长上下文大小,建议15,太短太长都会导致脑袋尖尖