refactor(chat): 优化异步任务处理和消息管理逻辑

- 使用asyncio.create_task替代await调用,提升并发性能
- 简化流管理器的槽位获取逻辑,移除回退方案
- 重构上下文管理器的消息添加和更新机制
- 移除StreamContext中的冗余方法,保持数据模型的简洁性
- 优化兴趣度评分系统的更新流程,减少阻塞操作

这些改动主要关注性能优化和代码结构简化,不涉及功能变更。
This commit is contained in:
Windpicker-owo
2025-10-05 15:17:30 +08:00
parent 5edf50705c
commit 23e523c7b9
9 changed files with 92 additions and 255 deletions

View File

@@ -175,7 +175,6 @@ class PromptManager:
self._prompts = {}
self._counter = 0
self._context = PromptContext()
self._lock = asyncio.Lock()
@asynccontextmanager
async def async_message_scope(self, message_id: str | None = None):
@@ -190,10 +189,9 @@ class PromptManager:
logger.debug(f"从上下文中获取提示词: {name} {context_prompt}")
return context_prompt
async with self._lock:
if name not in self._prompts:
raise KeyError(f"Prompt '{name}' not found")
return self._prompts[name]
if name not in self._prompts:
raise KeyError(f"Prompt '{name}' not found")
return self._prompts[name]
def generate_name(self, template: str) -> str:
"""为未命名的prompt生成名称"""