refactor(config): rename wakeup_system to sleep_system for clarity
This commit refactors the entire "wakeup system" to be named "sleep system". This change provides a more intuitive and accurate name for the functionality, which manages the AI's sleep cycles, sleep pressure, and related behaviors like insomnia and flexible sleep schedules. The renaming has been applied consistently across all relevant files, including: - Configuration models (`WakeUpSystemConfig` -> `SleepSystemConfig`) - Configuration files (`bot_config_template.toml`) - Core application logic that references these configurations. Additionally, flexible sleep and pre-sleep notification settings have been moved from the `ScheduleConfig` to the new `SleepSystemConfig` to centralize all sleep-related parameters.
This commit is contained in:
committed by
Windpicker-owo
parent
1dbf14c096
commit
0d072f5059
@@ -133,7 +133,7 @@ class CycleProcessor:
|
||||
await stop_typing()
|
||||
|
||||
# 在一轮动作执行完毕后,增加睡眠压力
|
||||
if self.context.energy_manager and global_config.wakeup_system.enable_insomnia_system:
|
||||
if self.context.energy_manager and global_config.sleep_system.enable_insomnia_system:
|
||||
if action_type not in ["no_reply", "no_action"]:
|
||||
self.context.energy_manager.increase_sleep_pressure()
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class EnergyManager:
|
||||
|
||||
if is_sleeping:
|
||||
# 睡眠中:减少睡眠压力
|
||||
decay_per_10s = global_config.wakeup_system.sleep_pressure_decay_rate / 6
|
||||
decay_per_10s = global_config.sleep_system.sleep_pressure_decay_rate / 6
|
||||
self.context.sleep_pressure -= decay_per_10s
|
||||
self.context.sleep_pressure = max(self.context.sleep_pressure, 0)
|
||||
self._log_sleep_pressure_change("睡眠压力释放")
|
||||
@@ -145,7 +145,7 @@ class EnergyManager:
|
||||
"""
|
||||
在执行动作后增加睡眠压力
|
||||
"""
|
||||
increment = global_config.wakeup_system.sleep_pressure_increment
|
||||
increment = global_config.sleep_system.sleep_pressure_increment
|
||||
self.context.sleep_pressure += increment
|
||||
self.context.sleep_pressure = min(self.context.sleep_pressure, 100.0) # 设置一个100的上限
|
||||
self._log_sleep_pressure_change("执行动作,睡眠压力累积")
|
||||
|
||||
@@ -209,12 +209,12 @@ class HeartFChatting:
|
||||
if self.wakeup_manager and self.wakeup_manager.check_for_insomnia():
|
||||
# 触发失眠
|
||||
self.context.is_in_insomnia = True
|
||||
duration = global_config.wakeup_system.insomnia_duration_minutes * 60
|
||||
duration = global_config.sleep_system.insomnia_duration_minutes * 60
|
||||
self.context.insomnia_end_time = time.time() + duration
|
||||
|
||||
# 判断失眠原因并触发思考
|
||||
reason = "random"
|
||||
if self.context.sleep_pressure < global_config.wakeup_system.sleep_pressure_threshold:
|
||||
if self.context.sleep_pressure < global_config.sleep_system.sleep_pressure_threshold:
|
||||
reason = "low_pressure"
|
||||
await self.proactive_thinker.trigger_insomnia_thinking(reason)
|
||||
|
||||
@@ -274,7 +274,7 @@ class HeartFChatting:
|
||||
# --- 重新入睡逻辑 ---
|
||||
# 如果被吵醒了,并且在一定时间内没有新消息,则尝试重新入睡
|
||||
if schedule_manager._is_woken_up and not has_new_messages:
|
||||
re_sleep_delay = global_config.wakeup_system.re_sleep_delay_minutes * 60
|
||||
re_sleep_delay = global_config.sleep_system.re_sleep_delay_minutes * 60
|
||||
# 使用 last_message_time 来判断空闲时间
|
||||
if time.time() - self.context.last_message_time > re_sleep_delay:
|
||||
logger.info(f"{self.context.log_prefix} 已被唤醒且超过 {re_sleep_delay / 60} 分钟无新消息,尝试重新入睡。")
|
||||
|
||||
@@ -31,22 +31,22 @@ class WakeUpManager:
|
||||
self.log_interval = 30
|
||||
|
||||
# 从配置文件获取参数
|
||||
wakeup_config = global_config.wakeup_system
|
||||
self.wakeup_threshold = wakeup_config.wakeup_threshold
|
||||
self.private_message_increment = wakeup_config.private_message_increment
|
||||
self.group_mention_increment = wakeup_config.group_mention_increment
|
||||
self.decay_rate = wakeup_config.decay_rate
|
||||
self.decay_interval = wakeup_config.decay_interval
|
||||
self.angry_duration = wakeup_config.angry_duration
|
||||
self.enabled = wakeup_config.enable
|
||||
self.angry_prompt = wakeup_config.angry_prompt
|
||||
sleep_config = global_config.sleep_system
|
||||
self.wakeup_threshold = sleep_config.wakeup_threshold
|
||||
self.private_message_increment = sleep_config.private_message_increment
|
||||
self.group_mention_increment = sleep_config.group_mention_increment
|
||||
self.decay_rate = sleep_config.decay_rate
|
||||
self.decay_interval = sleep_config.decay_interval
|
||||
self.angry_duration = sleep_config.angry_duration
|
||||
self.enabled = sleep_config.enable
|
||||
self.angry_prompt = sleep_config.angry_prompt
|
||||
|
||||
# 失眠系统参数
|
||||
self.insomnia_enabled = wakeup_config.enable_insomnia_system
|
||||
self.sleep_pressure_threshold = wakeup_config.sleep_pressure_threshold
|
||||
self.deep_sleep_threshold = wakeup_config.deep_sleep_threshold
|
||||
self.insomnia_chance_low_pressure = wakeup_config.insomnia_chance_low_pressure
|
||||
self.insomnia_chance_normal_pressure = wakeup_config.insomnia_chance_normal_pressure
|
||||
self.insomnia_enabled = sleep_config.enable_insomnia_system
|
||||
self.sleep_pressure_threshold = sleep_config.sleep_pressure_threshold
|
||||
self.deep_sleep_threshold = sleep_config.deep_sleep_threshold
|
||||
self.insomnia_chance_low_pressure = sleep_config.insomnia_chance_low_pressure
|
||||
self.insomnia_chance_normal_pressure = sleep_config.insomnia_chance_normal_pressure
|
||||
|
||||
self._load_wakeup_state()
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ from src.config.official_configs import (
|
||||
WebSearchConfig,
|
||||
AntiPromptInjectionConfig,
|
||||
PluginsConfig,
|
||||
WakeUpSystemConfig,
|
||||
SleepSystemConfig,
|
||||
MonthlyPlanSystemConfig,
|
||||
CrossContextConfig,
|
||||
PermissionConfig,
|
||||
@@ -404,7 +404,7 @@ class Config(ValidatedConfigBase):
|
||||
dependency_management: DependencyManagementConfig = Field(default_factory=lambda: DependencyManagementConfig(), description="依赖管理配置")
|
||||
web_search: WebSearchConfig = Field(default_factory=lambda: WebSearchConfig(), description="网络搜索配置")
|
||||
plugins: PluginsConfig = Field(default_factory=lambda: PluginsConfig(), description="插件配置")
|
||||
wakeup_system: WakeUpSystemConfig = Field(default_factory=lambda: WakeUpSystemConfig(), description="唤醒度系统配置")
|
||||
sleep_system: SleepSystemConfig = Field(default_factory=lambda: SleepSystemConfig(), description="睡眠系统配置")
|
||||
monthly_plan_system: MonthlyPlanSystemConfig = Field(default_factory=lambda: MonthlyPlanSystemConfig(), description="月层计划系统配置")
|
||||
cross_context: CrossContextConfig = Field(default_factory=lambda: CrossContextConfig(), description="跨群聊上下文共享配置")
|
||||
maizone_intercom: MaizoneIntercomConfig = Field(default_factory=lambda: MaizoneIntercomConfig(), description="Maizone互通组配置")
|
||||
|
||||
@@ -530,15 +530,6 @@ class ScheduleConfig(ValidatedConfigBase):
|
||||
enable: bool = Field(default=True, description="启用")
|
||||
guidelines: Optional[str] = Field(default=None, description="指导方针")
|
||||
enable_is_sleep: bool = Field(default=True, description="让AI会根据日程表睡觉和苏醒")
|
||||
|
||||
enable_flexible_sleep: bool = Field(default=True, description="是否启用弹性睡眠")
|
||||
flexible_sleep_pressure_threshold: float = Field(default=40.0, description="触发弹性睡眠的睡眠压力阈值,低于该值可能延迟入睡")
|
||||
max_sleep_delay_minutes: int = Field(default=60, description="单日最大延迟入睡分钟数")
|
||||
|
||||
enable_pre_sleep_notification: bool = Field(default=True, description="是否启用睡前消息")
|
||||
pre_sleep_notification_groups: List[str] = Field(default_factory=list, description="接收睡前消息的群号列表, 格式: [\"platform:group_id1\", \"platform:group_id2\"]")
|
||||
pre_sleep_prompt: str = Field(default="我准备睡觉了,请生成一句简短自然的晚安问候。", description="用于生成睡前消息的提示")
|
||||
|
||||
|
||||
|
||||
class DependencyManagementConfig(ValidatedConfigBase):
|
||||
@@ -617,10 +608,10 @@ class PluginsConfig(ValidatedConfigBase):
|
||||
centralized_config: bool = Field(default=True, description="是否启用插件配置集中化管理")
|
||||
|
||||
|
||||
class WakeUpSystemConfig(ValidatedConfigBase):
|
||||
"""唤醒度与失眠系统配置类"""
|
||||
class SleepSystemConfig(ValidatedConfigBase):
|
||||
"""睡眠系统配置类"""
|
||||
|
||||
enable: bool = Field(default=True, description="是否启用唤醒度系统")
|
||||
enable: bool = Field(default=True, description="是否启用睡眠系统")
|
||||
wakeup_threshold: float = Field(default=15.0, ge=1.0, description="唤醒阈值,达到此值时会被唤醒")
|
||||
private_message_increment: float = Field(default=3.0, ge=0.1, description="私聊消息增加的唤醒度")
|
||||
group_mention_increment: float = Field(default=2.0, ge=0.1, description="群聊艾特增加的唤醒度")
|
||||
@@ -640,6 +631,14 @@ class WakeUpSystemConfig(ValidatedConfigBase):
|
||||
sleep_pressure_increment: float = Field(default=1.5, ge=0.0, description="每次AI执行动作后,增加的睡眠压力值")
|
||||
sleep_pressure_decay_rate: float = Field(default=1.5, ge=0.0, description="睡眠时,每分钟衰减的睡眠压力值")
|
||||
|
||||
# --- 弹性睡眠与睡前消息 ---
|
||||
enable_flexible_sleep: bool = Field(default=True, description="是否启用弹性睡眠")
|
||||
flexible_sleep_pressure_threshold: float = Field(default=40.0, description="触发弹性睡眠的睡眠压力阈值,低于该值可能延迟入睡")
|
||||
max_sleep_delay_minutes: int = Field(default=60, description="单日最大延迟入睡分钟数")
|
||||
enable_pre_sleep_notification: bool = Field(default=True, description="是否启用睡前消息")
|
||||
pre_sleep_notification_groups: List[str] = Field(default_factory=list, description="接收睡前消息的群号列表, 格式: [\"platform:group_id1\", \"platform:group_id2\"]")
|
||||
pre_sleep_prompt: str = Field(default="我准备睡觉了,请生成一句简短自然的晚安问候。", description="用于生成睡前消息的提示")
|
||||
|
||||
|
||||
class MonthlyPlanSystemConfig(ValidatedConfigBase):
|
||||
"""月度计划系统配置类"""
|
||||
|
||||
@@ -89,6 +89,7 @@ learning_strength = 1.0
|
||||
|
||||
[[expression.rules]]
|
||||
chat_stream_id = "qq:1919810:group"
|
||||
group = "group_A"
|
||||
use_expression = true
|
||||
learn_expression = true
|
||||
learning_strength = 1.5
|
||||
@@ -100,29 +101,18 @@ use_expression = true
|
||||
learn_expression = false
|
||||
learning_strength = 0.5
|
||||
|
||||
[[expression.rules]]
|
||||
chat_stream_id = "qq:1919810:private"
|
||||
group = "group_A"
|
||||
use_expression = true
|
||||
learn_expression = true
|
||||
learning_strength = 1.0
|
||||
|
||||
|
||||
|
||||
[chat] #MoFox-Bot的聊天通用设置
|
||||
# 群聊聊天模式设置
|
||||
group_chat_mode = "auto" # 群聊聊天模式:auto-自动切换,normal-强制普通模式,focus-强制专注模式
|
||||
focus_value = 1
|
||||
# MoFox-Bot的专注思考能力,越高越容易专注,可能消耗更多token
|
||||
# MoFox-Bot的专注思考能力,越高越容易专注,可能消耗更多token,仅限自动切换模式下使用哦
|
||||
# 专注时能更好把握发言时机,能够进行持久的连续对话
|
||||
|
||||
talk_frequency = 1 # MoFox-Bot活跃度,越高,MoFox-Bot回复越频繁
|
||||
talk_frequency = 1 # MoFox-Bot活跃度,越高,MoFox-Bot回复越频繁,仅限normal/或者自动切换的normal模式下使用哦
|
||||
|
||||
# 强制私聊专注模式
|
||||
force_focus_private = false # 是否强制私聊进入专注模式,开启后私聊将始终保持专注状态
|
||||
|
||||
# 群聊聊天模式设置
|
||||
group_chat_mode = "auto" # 群聊聊天模式:auto-自动切换,normal-强制普通模式,focus-强制专注模式
|
||||
|
||||
|
||||
max_context_size = 25 # 上下文长度
|
||||
thinking_timeout = 40 # MoFox-Bot一次回复最长思考规划时间,超过这个时间的思考会放弃(往往是api反应太慢)
|
||||
replyer_random_probability = 0.5 # 首要replyer模型被选择的概率
|
||||
@@ -278,7 +268,7 @@ enable_vector_instant_memory = true # 是否启用基于向量的瞬时记忆
|
||||
memory_ban_words = [ "表情包", "图片", "回复", "聊天记录" ]
|
||||
|
||||
[voice]
|
||||
enable_asr = false # 是否启用语音识别,启用后MoFox-Bot可以识别语音消息,启用该功能需要配置语音识别模型[model.voice]s
|
||||
enable_asr = false # 是否启用语音识别,启用后MoFox-Bot可以识别语音消息,启用该功能需要配置语音识别模型[model.voice]
|
||||
|
||||
[lpmm_knowledge] # lpmm知识库配置
|
||||
enable = false # 是否启用lpmm知识库
|
||||
@@ -381,23 +371,6 @@ guidelines = """
|
||||
晚上我希望你能多和朋友们交流,维系好彼此的关系。
|
||||
另外,请保证充足的休眠时间来处理和整合一天的数据。
|
||||
"""
|
||||
enable_is_sleep = false
|
||||
|
||||
# --- 弹性睡眠与睡前消息 ---
|
||||
# 是否启用弹性睡眠。启用后,AI不会到点立刻入睡,而是会根据睡眠压力增加5-10分钟的缓冲,并可能因为压力不足而推迟睡眠。
|
||||
enable_flexible_sleep = true
|
||||
# 触发弹性睡眠的睡眠压力阈值。当AI的睡眠压力低于此值时,可能会推迟入睡。
|
||||
flexible_sleep_pressure_threshold = 40.0
|
||||
# 每日最大可推迟入睡的总分钟数。
|
||||
max_sleep_delay_minutes = 60
|
||||
|
||||
# 是否在进入“准备入睡”状态时发送一条消息通知。
|
||||
enable_pre_sleep_notification = true
|
||||
# 接收睡前消息的群组列表。格式为: ["platform:group_id1", "platform:group_id2"],例如 ["qq:12345678"]
|
||||
pre_sleep_notification_groups = []
|
||||
# 用于生成睡前消息的提示。AI会根据这个提示生成一句晚安问候。
|
||||
pre_sleep_prompt = "我准备睡觉了,请生成一句简短自然的晚安问候。"
|
||||
|
||||
[video_analysis] # 视频分析配置
|
||||
enable = true # 是否启用视频分析功能
|
||||
analysis_mode = "batch_frames" # 分析模式:"frame_by_frame"(逐帧分析,非常慢)、"batch_frames"(批量分析,推荐)或 "auto"(自动选择)
|
||||
@@ -468,8 +441,8 @@ guidelines = """
|
||||
请确保计划既有挑战性又不会过于繁重,保持生活的平衡和乐趣。
|
||||
"""
|
||||
|
||||
[wakeup_system]
|
||||
enable = false #"是否启用唤醒度系统"
|
||||
[sleep_system]
|
||||
enable = false #"是否启用睡眠系统"
|
||||
wakeup_threshold = 15.0 #唤醒阈值,达到此值时会被唤醒"
|
||||
private_message_increment = 3.0 #"私聊消息增加的唤醒度"
|
||||
group_mention_increment = 2.0 #"群聊艾特增加的唤醒度"
|
||||
@@ -494,6 +467,21 @@ sleep_pressure_increment = 1.5
|
||||
sleep_pressure_decay_rate = 1.5
|
||||
insomnia_duration_minutes = 30 # 单次失眠状态的持续时间(分钟)
|
||||
|
||||
# --- 弹性睡眠与睡前消息 ---
|
||||
# 是否启用弹性睡眠。启用后,AI不会到点立刻入睡,而是会根据睡眠压力增加5-10分钟的缓冲,并可能因为压力不足而推迟睡眠。
|
||||
enable_flexible_sleep = false
|
||||
# 触发弹性睡眠的睡眠压力阈值。当AI的睡眠压力低于此值时,可能会推迟入睡。
|
||||
flexible_sleep_pressure_threshold = 40.0
|
||||
# 每日最大可推迟入睡的总分钟数。
|
||||
max_sleep_delay_minutes = 60
|
||||
|
||||
# 是否在进入“准备入睡”状态时发送一条消息通知。
|
||||
enable_pre_sleep_notification = false
|
||||
# 接收睡前消息的群组列表。格式为: ["platform:group_id1", "platform:group_id2"],例如 ["qq:12345678"]
|
||||
pre_sleep_notification_groups = []
|
||||
# 用于生成睡前消息的提示。AI会根据这个提示生成一句晚安问候。
|
||||
pre_sleep_prompt = "我准备睡觉了,请生成一句简短自然的晚安问候。"
|
||||
|
||||
[cross_context] # 跨群聊上下文共享配置
|
||||
# 这是总开关,用于一键启用或禁用此功能
|
||||
enable = false
|
||||
|
||||
Reference in New Issue
Block a user