better:重整配置,分离表达,聊天模式区分
重整配置文件路径,添加更多配置选项 分离了人设表达方式和学习到的表达方式 将聊天模式区分为normal focus和auto
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import Optional, Coroutine, Callable, Any, List
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.chat.heart_flow.mai_state_manager import MaiStateManager, MaiStateInfo
|
||||
from src.chat.heart_flow.subheartflow_manager import SubHeartflowManager
|
||||
|
||||
from src.config.config import global_config
|
||||
|
||||
logger = get_logger("background_tasks")
|
||||
|
||||
@@ -94,13 +94,6 @@ class BackgroundTaskManager:
|
||||
f"清理任务已启动 间隔:{CLEANUP_INTERVAL_SECONDS}s",
|
||||
"_cleanup_task",
|
||||
),
|
||||
# 新增兴趣评估任务配置
|
||||
(
|
||||
self._run_into_focus_cycle,
|
||||
"debug", # 设为debug,避免过多日志
|
||||
f"专注评估任务已启动 间隔:{INTEREST_EVAL_INTERVAL_SECONDS}s",
|
||||
"_into_focus_task",
|
||||
),
|
||||
# 新增私聊激活任务配置
|
||||
(
|
||||
# Use lambda to pass the interval to the runner function
|
||||
@@ -111,6 +104,19 @@ class BackgroundTaskManager:
|
||||
),
|
||||
]
|
||||
|
||||
# 根据 chat_mode 条件添加专注评估任务
|
||||
if not (global_config.chat.chat_mode == "normal"):
|
||||
task_configs.append(
|
||||
(
|
||||
self._run_into_focus_cycle,
|
||||
"debug", # 设为debug,避免过多日志
|
||||
f"专注评估任务已启动 间隔:{INTEREST_EVAL_INTERVAL_SECONDS}s",
|
||||
"_into_focus_task",
|
||||
)
|
||||
)
|
||||
else:
|
||||
logger.info("聊天模式为 normal,跳过启动专注评估任务")
|
||||
|
||||
# 统一启动所有任务
|
||||
for task_func, log_level, log_msg, task_attr_name in task_configs:
|
||||
# 检查任务变量是否存在且未完成
|
||||
@@ -183,7 +189,6 @@ class BackgroundTaskManager:
|
||||
logger.info("检测到离线,停用所有子心流")
|
||||
await self.subheartflow_manager.deactivate_all_subflows()
|
||||
|
||||
|
||||
async def _perform_cleanup_work(self):
|
||||
"""执行子心流清理任务
|
||||
1. 获取需要清理的不活跃子心流列表
|
||||
@@ -209,18 +214,15 @@ class BackgroundTaskManager:
|
||||
# 记录最终清理结果
|
||||
logger.info(f"[清理任务] 清理完成, 共停止 {stopped_count}/{len(flows_to_stop)} 个子心流")
|
||||
|
||||
|
||||
# --- 新增兴趣评估工作函数 ---
|
||||
async def _perform_into_focus_work(self):
|
||||
"""执行一轮子心流兴趣评估与提升检查。"""
|
||||
# 直接调用 subheartflow_manager 的方法,并传递当前状态信息
|
||||
await self.subheartflow_manager.sbhf_absent_into_focus()
|
||||
|
||||
await self.subheartflow_manager.sbhf_normal_into_focus()
|
||||
|
||||
async def _run_state_update_cycle(self, interval: int):
|
||||
await _run_periodic_loop(task_name="State Update", interval=interval, task_func=self._perform_state_update_work)
|
||||
|
||||
|
||||
|
||||
async def _run_cleanup_cycle(self):
|
||||
await _run_periodic_loop(
|
||||
task_name="Subflow Cleanup", interval=CLEANUP_INTERVAL_SECONDS, task_func=self._perform_cleanup_work
|
||||
|
||||
Reference in New Issue
Block a user