🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-07-05 11:31:56 +00:00
parent 40109b2e66
commit 324b4b1b3f
2 changed files with 19 additions and 13 deletions

View File

@@ -447,23 +447,23 @@ class SubHeartflow:
def get_cooldown_progress(self) -> float: def get_cooldown_progress(self) -> float:
"""获取冷却进度返回0-1之间的值 """获取冷却进度返回0-1之间的值
Returns: Returns:
float: 0表示刚开始冷却1表示冷却完成 float: 0表示刚开始冷却1表示冷却完成
""" """
if self.last_focus_exit_time == 0: if self.last_focus_exit_time == 0:
return 1.0 # 没有冷却返回1表示完全恢复 return 1.0 # 没有冷却返回1表示完全恢复
# 基础冷却时间10分钟受auto_focus_threshold调控 # 基础冷却时间10分钟受auto_focus_threshold调控
base_cooldown = 10 * 60 # 10分钟转换为秒 base_cooldown = 10 * 60 # 10分钟转换为秒
cooldown_duration = base_cooldown / global_config.chat.auto_focus_threshold cooldown_duration = base_cooldown / global_config.chat.auto_focus_threshold
current_time = time.time() current_time = time.time()
elapsed_since_exit = current_time - self.last_focus_exit_time elapsed_since_exit = current_time - self.last_focus_exit_time
if elapsed_since_exit >= cooldown_duration: if elapsed_since_exit >= cooldown_duration:
return 1.0 # 冷却完成 return 1.0 # 冷却完成
# 计算进度0表示刚开始冷却1表示冷却完成 # 计算进度0表示刚开始冷却1表示冷却完成
progress = elapsed_since_exit / cooldown_duration progress = elapsed_since_exit / cooldown_duration
return progress return progress

View File

@@ -54,7 +54,13 @@ class NormalChat:
每个聊天私聊或群聊都会有一个独立的NormalChat实例。 每个聊天私聊或群聊都会有一个独立的NormalChat实例。
""" """
def __init__(self, chat_stream: ChatStream, interest_dict: dict = None, on_switch_to_focus_callback=None, get_cooldown_progress_callback=None): def __init__(
self,
chat_stream: ChatStream,
interest_dict: dict = None,
on_switch_to_focus_callback=None,
get_cooldown_progress_callback=None,
):
""" """
初始化NormalChat实例。 初始化NormalChat实例。
@@ -109,7 +115,7 @@ class NormalChat:
# 添加回调函数用于在满足条件时通知切换到focus_chat模式 # 添加回调函数用于在满足条件时通知切换到focus_chat模式
self.on_switch_to_focus_callback = on_switch_to_focus_callback self.on_switch_to_focus_callback = on_switch_to_focus_callback
# 添加回调函数,用于获取冷却进度 # 添加回调函数,用于获取冷却进度
self.get_cooldown_progress_callback = get_cooldown_progress_callback self.get_cooldown_progress_callback = get_cooldown_progress_callback
@@ -774,7 +780,7 @@ class NormalChat:
fatigue_multiplier = self._get_fatigue_reply_multiplier() fatigue_multiplier = self._get_fatigue_reply_multiplier()
original_probability = reply_probability original_probability = reply_probability
reply_probability *= fatigue_multiplier reply_probability *= fatigue_multiplier
# 如果应用了疲劳调整,记录日志 # 如果应用了疲劳调整,记录日志
if fatigue_multiplier < 1.0: if fatigue_multiplier < 1.0:
logger.info( logger.info(
@@ -1339,23 +1345,23 @@ class NormalChat:
def _get_fatigue_reply_multiplier(self) -> float: def _get_fatigue_reply_multiplier(self) -> float:
"""获取疲劳期回复频率调整系数 """获取疲劳期回复频率调整系数
Returns: Returns:
float: 回复频率调整系数范围0.5-1.0 float: 回复频率调整系数范围0.5-1.0
""" """
if not self.get_cooldown_progress_callback: if not self.get_cooldown_progress_callback:
return 1.0 # 没有冷却进度回调,返回正常系数 return 1.0 # 没有冷却进度回调,返回正常系数
try: try:
cooldown_progress = self.get_cooldown_progress_callback() cooldown_progress = self.get_cooldown_progress_callback()
if cooldown_progress >= 1.0: if cooldown_progress >= 1.0:
return 1.0 # 冷却完成,正常回复频率 return 1.0 # 冷却完成,正常回复频率
# 疲劳期间从0.5逐渐恢复到1.0 # 疲劳期间从0.5逐渐恢复到1.0
# progress=0时系数为0.5progress=1时系数为1.0 # progress=0时系数为0.5progress=1时系数为1.0
multiplier = 0.2 + (0.8 * cooldown_progress) multiplier = 0.2 + (0.8 * cooldown_progress)
return multiplier return multiplier
except Exception as e: except Exception as e:
logger.warning(f"[{self.stream_name}] 获取疲劳调整系数时出错: {e}") logger.warning(f"[{self.stream_name}] 获取疲劳调整系数时出错: {e}")