better:优化focus控制和no_reply控制

This commit is contained in:
SengokuCola
2025-07-26 11:01:55 +08:00
parent ae0fb7c6c4
commit 4411859e37
5 changed files with 27 additions and 33 deletions

View File

@@ -88,11 +88,6 @@ class HeartFChatting:
self.loop_mode = ChatMode.NORMAL # 初始循环模式为普通模式 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_manager = ActionManager()
self.action_planner = ActionPlanner(chat_id=self.stream_id, action_manager=self.action_manager) 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) 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.last_read_time = time.time() - 1
self.willing_amplifier = 1
self.willing_manager = get_willing_manager() self.willing_manager = get_willing_manager()
logger.info(f"{self.log_prefix} HeartFChatting 初始化完成") logger.info(f"{self.log_prefix} HeartFChatting 初始化完成")
@@ -182,6 +176,9 @@ class HeartFChatting:
if self.loop_mode == ChatMode.NORMAL: if self.loop_mode == ChatMode.NORMAL:
self.energy_value -= 0.3 self.energy_value -= 0.3
self.energy_value = max(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): def print_cycle_info(self, cycle_timers):
# 记录循环信息和计时器结果 # 记录循环信息和计时器结果
@@ -200,9 +197,9 @@ class HeartFChatting:
async def _loopbody(self): async def _loopbody(self):
if self.loop_mode == ChatMode.FOCUS: if self.loop_mode == ChatMode.FOCUS:
if await self._observe(): if await self._observe():
self.energy_value -= 1 * global_config.chat.focus_value self.energy_value -= 1 / global_config.chat.focus_value
else: else:
self.energy_value -= 3 * global_config.chat.focus_value self.energy_value -= 3 / global_config.chat.focus_value
if self.energy_value <= 1: if self.energy_value <= 1:
self.energy_value = 1 self.energy_value = 1
self.loop_mode = ChatMode.NORMAL self.loop_mode = ChatMode.NORMAL
@@ -219,12 +216,12 @@ class HeartFChatting:
filter_bot=True, 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.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 return True
if self.energy_value >= 30 * global_config.chat.focus_value: if self.energy_value >= 30:
self.loop_mode = ChatMode.FOCUS self.loop_mode = ChatMode.FOCUS
return True return True
@@ -235,10 +232,10 @@ class HeartFChatting:
if_think = await self.normal_response(earliest_messages_data) if_think = await self.normal_response(earliest_messages_data)
if if_think: if if_think:
factor = max(global_config.chat.focus_value, 0.1) 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}") logger.info(f"{self.log_prefix} 进行了思考,能量值按倍数增加,当前能量值:{self.energy_value:.1f}")
else: 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}")
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) self.willing_manager.setup(message_data, self.chat_stream)

View File

@@ -28,7 +28,7 @@ class ClassicalWillingManager(BaseWillingManager):
# print(f"[{chat_id}] 回复意愿: {current_willing}") # 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}") # print(f"[{chat_id}] 兴趣值: {interested_rate}")

View File

@@ -69,6 +69,8 @@ class ChatConfig(ConfigBase):
max_context_size: int = 18 max_context_size: int = 18
"""上下文长度""" """上下文长度"""
willing_amplifier: float = 1.0
replyer_random_probability: float = 0.5 replyer_random_probability: float = 0.5
""" """
发言时选择推理模型的概率0-1之间 发言时选择推理模型的概率0-1之间
@@ -273,12 +275,6 @@ class NormalChatConfig(ConfigBase):
willing_mode: str = "classical" willing_mode: str = "classical"
"""意愿模式""" """意愿模式"""
response_interested_rate_amplifier: float = 1.0
"""回复兴趣度放大系数"""
@dataclass @dataclass
class ExpressionConfig(ConfigBase): class ExpressionConfig(ConfigBase):
"""表达配置类""" """表达配置类"""

View File

@@ -39,14 +39,14 @@ class NoReplyAction(BaseAction):
# 新增:兴趣值退出阈值 # 新增:兴趣值退出阈值
_interest_exit_threshold = 3.0 _interest_exit_threshold = 3.0
# 新增:消息数量退出阈值 # 新增:消息数量退出阈值
_min_exit_message_count = 5 _min_exit_message_count = 3
_max_exit_message_count = 10 _max_exit_message_count = 6
# 动作参数定义 # 动作参数定义
action_parameters = {} action_parameters = {}
# 动作使用场景 # 动作使用场景
action_require = ["你发送了消息,目前无人回复"] action_require = [""]
# 关联类型 # 关联类型
associated_types = [] 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) 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}") logger.info(f"{self.log_prefix} 选择不回复(第{count}次),开始摸鱼,原因: {reason}")
@@ -89,9 +86,12 @@ class NoReplyAction(BaseAction):
# 2. 检查消息数量是否达到阈值 # 2. 检查消息数量是否达到阈值
talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id) 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( 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}条新消息,可以考虑一下是否要进行回复" exit_reason = f"{global_config.bot.nickname}(你)看到了{new_message_count}条新消息,可以考虑一下是否要进行回复"
await self.store_action_info( await self.store_action_info(
@@ -108,7 +108,7 @@ class NoReplyAction(BaseAction):
text = msg_dict.get("processed_plain_text", "") text = msg_dict.get("processed_plain_text", "")
interest_value = msg_dict.get("interest_value", 0.0) interest_value = msg_dict.get("interest_value", 0.0)
if text: 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) talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id)
# 只在兴趣值变化时输出log # 只在兴趣值变化时输出log

View File

@@ -1,5 +1,5 @@
[inner] [inner]
version = "4.4.8" version = "4.4.9"
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
#如果你想要修改配置文件请在修改后将version的值进行变更 #如果你想要修改配置文件请在修改后将version的值进行变更
@@ -52,9 +52,11 @@ relation_frequency = 1 # 关系频率,麦麦构建关系的频率
[chat] #麦麦的聊天通用设置 [chat] #麦麦的聊天通用设置
focus_value = 1 focus_value = 1
# 麦麦的专注思考能力,越越容易专注,消耗token也越多 # 麦麦的专注思考能力,越越容易专注,可能消耗更多token
# 专注时能更好把握发言时机,能够进行持久的连续对话 # 专注时能更好把握发言时机,能够进行持久的连续对话
willing_amplifier = 1 # 麦麦回复意愿
max_context_size = 25 # 上下文长度 max_context_size = 25 # 上下文长度
thinking_timeout = 20 # 麦麦一次回复最长思考规划时间超过这个时间的思考会放弃往往是api反应太慢 thinking_timeout = 20 # 麦麦一次回复最长思考规划时间超过这个时间的思考会放弃往往是api反应太慢
replyer_random_probability = 0.5 # 首要replyer模型被选择的概率 replyer_random_probability = 0.5 # 首要replyer模型被选择的概率
@@ -105,7 +107,6 @@ ban_msgs_regex = [
[normal_chat] #普通聊天 [normal_chat] #普通聊天
willing_mode = "classical" # 回复意愿模式 —— 经典模式classicalmxp模式mxp自定义模式custom需要你自己实现 willing_mode = "classical" # 回复意愿模式 —— 经典模式classicalmxp模式mxp自定义模式custom需要你自己实现
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数
[tool] [tool]
enable_in_normal_chat = false # 是否在普通聊天中启用工具 enable_in_normal_chat = false # 是否在普通聊天中启用工具