后台初始化组件,gc全局化避免每次回收触发GIL锁,音频定时发送

This commit is contained in:
Sakura-RanChen
2025-11-28 16:12:19 +08:00
parent 228596dbe3
commit fb5c35e6c9
11 changed files with 503 additions and 197 deletions
@@ -5,6 +5,7 @@ import os
import yaml
from config.config_loader import get_project_dir
from config.manage_api_client import save_mem_local_short
import asyncio
from core.utils.util import check_model_key
@@ -193,7 +194,13 @@ class MemoryProvider(MemoryProviderBase):
max_tokens=2000,
temperature=0.2,
)
save_mem_local_short(self.role_id, result)
# 使用异步版本,需要在事件循环中运行
try:
loop = asyncio.get_running_loop()
loop.create_task(save_mem_local_short(self.role_id, result))
except RuntimeError:
# 如果没有运行中的事件循环,创建一个新的
asyncio.run(save_mem_local_short(self.role_id, result))
logger.bind(tag=TAG).info(f"Save memory successful - Role: {self.role_id}")
return self.short_memory