FEAT:现在AI可以根据日程表决定睡不睡觉了
This commit is contained in:
@@ -24,6 +24,7 @@ from src.chat.willing.willing_manager import get_willing_manager
|
|||||||
from src.mais4u.mai_think import mai_thinking_manager
|
from src.mais4u.mai_think import mai_thinking_manager
|
||||||
from src.mais4u.constant_s4u import ENABLE_S4U
|
from src.mais4u.constant_s4u import ENABLE_S4U
|
||||||
from src.chat.chat_loop.hfc_utils import send_typing, stop_typing
|
from src.chat.chat_loop.hfc_utils import send_typing, stop_typing
|
||||||
|
from src.manager.schedule_manager import schedule_manager
|
||||||
|
|
||||||
ERROR_LOOP_INFO = {
|
ERROR_LOOP_INFO = {
|
||||||
"loop_plan_info": {
|
"loop_plan_info": {
|
||||||
@@ -176,7 +177,7 @@ class HeartFChatting:
|
|||||||
self.delta_sigma = getattr(global_config.chat, 'delta_sigma', 120)
|
self.delta_sigma = getattr(global_config.chat, 'delta_sigma', 120)
|
||||||
|
|
||||||
# 打印主动思考配置信息
|
# 打印主动思考配置信息
|
||||||
logger.info(f"{self.log_prefix} 主动思考配置: 启用={global_config.chat.enable_proactive_thinking}, "
|
logger.debug(f"{self.log_prefix} 主动思考配置: 启用={global_config.chat.enable_proactive_thinking}, "
|
||||||
f"旧范围={self.proactive_thinking_chat_scope}, 私聊={self.proactive_thinking_in_private}, "
|
f"旧范围={self.proactive_thinking_chat_scope}, 私聊={self.proactive_thinking_in_private}, "
|
||||||
f"群聊={self.proactive_thinking_in_group}, ID列表={self.proactive_thinking_ids}, "
|
f"群聊={self.proactive_thinking_in_group}, ID列表={self.proactive_thinking_ids}, "
|
||||||
f"基础间隔={global_config.chat.proactive_thinking_interval}s, Delta={self.delta_sigma}")
|
f"基础间隔={global_config.chat.proactive_thinking_interval}s, Delta={self.delta_sigma}")
|
||||||
@@ -522,10 +523,13 @@ class HeartFChatting:
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def _loopbody(self):
|
async def _loopbody(self):
|
||||||
|
if schedule_manager.is_sleeping():
|
||||||
|
return True
|
||||||
|
|
||||||
recent_messages_dict = message_api.get_messages_by_time_in_chat(
|
recent_messages_dict = message_api.get_messages_by_time_in_chat(
|
||||||
chat_id=self.stream_id,
|
chat_id=self.stream_id,
|
||||||
start_time=self.last_read_time,
|
start_time=self.last_read_time,
|
||||||
end_time=time.time(),
|
end_time=time.time(),
|
||||||
limit=10,
|
limit=10,
|
||||||
limit_mode="latest",
|
limit_mode="latest",
|
||||||
filter_mai=True,
|
filter_mai=True,
|
||||||
@@ -533,7 +537,7 @@ class HeartFChatting:
|
|||||||
)
|
)
|
||||||
new_message_count = len(recent_messages_dict)
|
new_message_count = len(recent_messages_dict)
|
||||||
|
|
||||||
# 如果有新消息,更新最后消息时间(用于主动思考计时)
|
# 如果有新消息,更新最后消息时间(用于主动思考计时)
|
||||||
if new_message_count > 0:
|
if new_message_count > 0:
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
self.last_message_time = current_time
|
self.last_message_time = current_time
|
||||||
|
|||||||
@@ -579,6 +579,7 @@ class ScheduleConfig(ValidatedConfigBase):
|
|||||||
|
|
||||||
enable: bool = Field(default=True, description="启用")
|
enable: bool = Field(default=True, description="启用")
|
||||||
guidelines: Optional[str] = Field(default=None, description="指导方针")
|
guidelines: Optional[str] = Field(default=None, description="指导方针")
|
||||||
|
enabe_is_sleep: bool = Field(default=True, description="让AI会根据日程表睡觉和苏醒")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -312,6 +312,43 @@ class ScheduleManager:
|
|||||||
continue
|
continue
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_sleeping(self) -> bool:
|
||||||
|
"""检查当前是否处于休眠时间(日程表的第一项或最后一项)"""
|
||||||
|
if not global_config.schedule.enabe_is_sleep:
|
||||||
|
return False
|
||||||
|
if not self.today_schedule:
|
||||||
|
return False
|
||||||
|
|
||||||
|
now = datetime.now().time()
|
||||||
|
|
||||||
|
# 修复:应该获取列表的第一个元素
|
||||||
|
first_item = self.today_schedule
|
||||||
|
last_item = self.today_schedule[-1]
|
||||||
|
|
||||||
|
for item in [first_item, last_item]:
|
||||||
|
try:
|
||||||
|
time_range = item.get("time_range")
|
||||||
|
if not time_range:
|
||||||
|
continue
|
||||||
|
|
||||||
|
start_str, end_str = time_range.split('-')
|
||||||
|
start_time = datetime.strptime(start_str.strip(), "%H:%M").time()
|
||||||
|
end_time = datetime.strptime(end_str.strip(), "%H:%M").time()
|
||||||
|
|
||||||
|
if start_time <= end_time:
|
||||||
|
# 同一天内的时间段
|
||||||
|
if start_time <= now < end_time:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# 跨天的时间段
|
||||||
|
if now >= start_time or now < end_time:
|
||||||
|
return True
|
||||||
|
except (ValueError, KeyError, AttributeError) as e:
|
||||||
|
logger.warning(f"解析休眠日程事件失败: {item}, 错误: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def _validate_schedule_with_pydantic(self, schedule_data) -> bool:
|
def _validate_schedule_with_pydantic(self, schedule_data) -> bool:
|
||||||
"""使用Pydantic验证日程数据格式和完整性"""
|
"""使用Pydantic验证日程数据格式和完整性"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -363,6 +363,7 @@ guidelines = """
|
|||||||
晚上我希望你能多和朋友们交流,维系好彼此的关系。
|
晚上我希望你能多和朋友们交流,维系好彼此的关系。
|
||||||
另外,请保证充足的休眠时间来处理和整合一天的数据。
|
另外,请保证充足的休眠时间来处理和整合一天的数据。
|
||||||
"""
|
"""
|
||||||
|
enabe_is_sleep = false
|
||||||
|
|
||||||
[experimental] #实验性功能
|
[experimental] #实验性功能
|
||||||
enable_friend_chat = false # 是否启用好友聊天
|
enable_friend_chat = false # 是否启用好友聊天
|
||||||
|
|||||||
Reference in New Issue
Block a user