feat:疲劳时降低回复频率
This commit is contained in:
@@ -126,6 +126,7 @@ class SubHeartflow:
|
||||
chat_stream=chat_stream,
|
||||
interest_dict=self.interest_dict,
|
||||
on_switch_to_focus_callback=self._handle_switch_to_focus_request,
|
||||
get_cooldown_progress_callback=self.get_cooldown_progress,
|
||||
)
|
||||
|
||||
logger.info(f"{log_prefix} 开始普通聊天,随便水群...")
|
||||
@@ -443,3 +444,26 @@ class SubHeartflow:
|
||||
)
|
||||
|
||||
return is_cooling
|
||||
|
||||
def get_cooldown_progress(self) -> float:
|
||||
"""获取冷却进度,返回0-1之间的值
|
||||
|
||||
Returns:
|
||||
float: 0表示刚开始冷却,1表示冷却完成
|
||||
"""
|
||||
if self.last_focus_exit_time == 0:
|
||||
return 1.0 # 没有冷却,返回1表示完全恢复
|
||||
|
||||
# 基础冷却时间10分钟,受auto_focus_threshold调控
|
||||
base_cooldown = 10 * 60 # 10分钟转换为秒
|
||||
cooldown_duration = base_cooldown / global_config.chat.auto_focus_threshold
|
||||
|
||||
current_time = time.time()
|
||||
elapsed_since_exit = current_time - self.last_focus_exit_time
|
||||
|
||||
if elapsed_since_exit >= cooldown_duration:
|
||||
return 1.0 # 冷却完成
|
||||
|
||||
# 计算进度:0表示刚开始冷却,1表示冷却完成
|
||||
progress = elapsed_since_exit / cooldown_duration
|
||||
return progress
|
||||
|
||||
@@ -54,7 +54,7 @@ class NormalChat:
|
||||
每个聊天(私聊或群聊)都会有一个独立的NormalChat实例。
|
||||
"""
|
||||
|
||||
def __init__(self, chat_stream: ChatStream, interest_dict: dict = None, on_switch_to_focus_callback=None):
|
||||
def __init__(self, chat_stream: ChatStream, interest_dict: dict = None, on_switch_to_focus_callback=None, get_cooldown_progress_callback=None):
|
||||
"""
|
||||
初始化NormalChat实例。
|
||||
|
||||
@@ -109,6 +109,9 @@ class NormalChat:
|
||||
|
||||
# 添加回调函数,用于在满足条件时通知切换到focus_chat模式
|
||||
self.on_switch_to_focus_callback = on_switch_to_focus_callback
|
||||
|
||||
# 添加回调函数,用于获取冷却进度
|
||||
self.get_cooldown_progress_callback = get_cooldown_progress_callback
|
||||
|
||||
self._disabled = False # 增加停用标志
|
||||
|
||||
@@ -767,6 +770,17 @@ class NormalChat:
|
||||
reply_probability += message.message_info.additional_config["maimcore_reply_probability_gain"]
|
||||
reply_probability = min(max(reply_probability, 0), 1) # 确保概率在 0-1 之间
|
||||
|
||||
# 应用疲劳期回复频率调整
|
||||
fatigue_multiplier = self._get_fatigue_reply_multiplier()
|
||||
original_probability = reply_probability
|
||||
reply_probability *= fatigue_multiplier
|
||||
|
||||
# 如果应用了疲劳调整,记录日志
|
||||
if fatigue_multiplier < 1.0:
|
||||
logger.info(
|
||||
f"[{self.stream_name}] 疲劳期回复频率调整: {original_probability * 100:.1f}% -> {reply_probability * 100:.1f}% (系数: {fatigue_multiplier:.2f})"
|
||||
)
|
||||
|
||||
# 打印消息信息
|
||||
mes_name = self.chat_stream.group_info.group_name if self.chat_stream.group_info else "私聊"
|
||||
# current_time = time.strftime("%H:%M:%S", time.localtime(message.message_info.time))
|
||||
@@ -1323,6 +1337,30 @@ class NormalChat:
|
||||
logger.error(f"[{self.stream_name}] 为 {person_id} 更新印象时发生错误: {e}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def _get_fatigue_reply_multiplier(self) -> float:
|
||||
"""获取疲劳期回复频率调整系数
|
||||
|
||||
Returns:
|
||||
float: 回复频率调整系数,范围0.5-1.0
|
||||
"""
|
||||
if not self.get_cooldown_progress_callback:
|
||||
return 1.0 # 没有冷却进度回调,返回正常系数
|
||||
|
||||
try:
|
||||
cooldown_progress = self.get_cooldown_progress_callback()
|
||||
|
||||
if cooldown_progress >= 1.0:
|
||||
return 1.0 # 冷却完成,正常回复频率
|
||||
|
||||
# 疲劳期间:从0.5逐渐恢复到1.0
|
||||
# progress=0时系数为0.5,progress=1时系数为1.0
|
||||
multiplier = 0.2 + (0.8 * cooldown_progress)
|
||||
|
||||
return multiplier
|
||||
except Exception as e:
|
||||
logger.warning(f"[{self.stream_name}] 获取疲劳调整系数时出错: {e}")
|
||||
return 1.0 # 出错时返回正常系数
|
||||
|
||||
async def _check_should_switch_to_focus(self) -> bool:
|
||||
"""
|
||||
检查是否满足切换到focus模式的条件
|
||||
|
||||
Reference in New Issue
Block a user