refactor(chat): 异步化聊天系统并重构兴趣值计算机制

将同步调用改为异步调用以提升性能,重构兴趣值计算流程以支持更灵活的组件化架构。主要改进包括:

- 异步化ChatManager相关方法,避免阻塞主线程
- 重构兴趣值计算系统,从插件内部计算改为通过兴趣管理器统一处理
- 新增should_act字段支持更细粒度的动作决策
- 优化初始化逻辑,避免构造函数中的异步操作
- 扩展插件系统支持兴趣计算器组件注册
- 更新数据库模型以支持新的兴趣值相关字段

这些改进提升了系统的响应性能和可扩展性,同时保持了API的向后兼容性。
This commit is contained in:
Windpicker-owo
2025-10-05 01:25:52 +08:00
parent 49025a4973
commit 624298e1b8
38 changed files with 1493 additions and 259 deletions

View File

@@ -79,8 +79,16 @@ class RelationshipFetcher:
model_set=model_config.model_task_config.utils_small, request_type="relation.fetch"
)
name = get_chat_manager().get_stream_name(self.chat_id)
self.log_prefix = f"[{name}] 实时信息"
self.log_prefix = f"[{self.chat_id}] 实时信息" # 初始化时使用chat_id稍后异步更新
self._log_prefix_initialized = False
async def _initialize_log_prefix(self):
"""异步初始化log_prefix"""
if not self._log_prefix_initialized:
from src.chat.message_receive.chat_stream import get_chat_manager
name = await get_chat_manager().get_stream_name(self.chat_id)
self.log_prefix = f"[{name}] 实时信息"
self._log_prefix_initialized = True
def _cleanup_expired_cache(self):
"""清理过期的信息缓存"""
@@ -94,6 +102,9 @@ class RelationshipFetcher:
async def build_relation_info(self, person_id, points_num=5):
"""构建详细的人物关系信息,包含从数据库中查询的丰富关系描述"""
# 初始化log_prefix
await self._initialize_log_prefix()
# 清理过期的信息缓存
self._cleanup_expired_cache()