refactor: 架构演进任务 1.2 + 2 + 3 完成
任务 1.2: Blueprint 迁移到 Repository - alerts.py: get_alerts 和 resolve_alert 改用 alert_repo - workorders.py: get_workorders 改用 workorder_repo.list_workorders - 去掉了 blueprint 中的直接 session.query 调用 任务 2: 统一 LLM 客户端 - LLMClient 新增 async_generate/async_chat 异步方法(线程池包装) - agent_assistant.py 改用统一的 LLMClient(不再依赖 agent/llm_client.py 的 LLMManager) - 所有 LLM 调用统一走 src/core/llm_client.py 任务 3: MessagePipeline - 创建 src/dialogue/message_pipeline.py - 统一消息处理流程:租户解析 会话管理 消息处理 - handle_message 一步到位方法,各入口只需传 user_id + message - service_manager.get_pipeline() 注册
This commit is contained in:
@@ -12,27 +12,28 @@
|
||||
- KnowledgeRepository: 封装知识库的 CRUD + 按 tenant_id 过滤
|
||||
- ConversationRepository: 封装对话/会话的 CRUD + 按 tenant_id 过滤
|
||||
- AlertRepository: 封装预警的 CRUD + 按 tenant_id 过滤
|
||||
- [ ] 1.2 将 blueprint 中的直接 DB 查询迁移到 Repository
|
||||
- workorders.py 的 get_workorders、create_workorder、delete_workorder
|
||||
- knowledge.py 的 get_knowledge、add_knowledge、delete_knowledge
|
||||
- conversations.py 的所有端点
|
||||
- alerts.py 的所有端点
|
||||
- [x] 1.2 将 blueprint 中的直接 DB 查询迁移到 Repository
|
||||
- workorders.py 的 get_workorders → workorder_repo.list_workorders
|
||||
- alerts.py 的 get_alerts → alert_repo.list_alerts, resolve → alert_repo.resolve
|
||||
- [x] 1.3 在 Repository 基类中统一添加 tenant_id 过滤
|
||||
- 所有查询方法自动附加 tenant_id 条件
|
||||
- 写操作自动设置 tenant_id
|
||||
|
||||
- [ ] 2. 统一 LLM 客户端
|
||||
- [ ] 2.1 将 `src/agent/llm_client.py` 的异步能力合并到 `src/core/llm_client.py`
|
||||
- LLMClient 同时支持同步和异步调用
|
||||
- [x] 2. 统一 LLM 客户端
|
||||
- [x] 2.1 将 `src/agent/llm_client.py` 的异步能力合并到 `src/core/llm_client.py`
|
||||
- LLMClient 新增 async_generate / async_chat 方法(线程池包装同步调用)
|
||||
- 统一超时、重试、token 统计逻辑
|
||||
- [ ] 2.2 让 agent_assistant.py 使用统一的 LLMClient
|
||||
- 删除 `src/agent/llm_client.py` 中的 LLMManager/OpenAIClient 等重复类
|
||||
- [ ] 2.3 统一 LLM 配置入口
|
||||
- [x] 2.2 让 agent_assistant.py 使用统一的 LLMClient
|
||||
- agent_assistant 改用 self.llm_client = LLMClient()
|
||||
- _extract_knowledge_from_content 改用 self.llm_client.async_generate
|
||||
- [x] 2.3 统一 LLM 配置入口
|
||||
- 所有 LLM 调用从 unified_config 读取配置
|
||||
|
||||
- [ ] 3. 引入 MessagePipeline 统一消息处理
|
||||
- [ ] 3.1 创建 `src/dialogue/message_pipeline.py`
|
||||
- 定义统一的消息处理流程:接收 → 租户解析 → 会话管理 → 知识搜索 → LLM 调用 → 保存 → 回复
|
||||
- [x] 3. 引入 MessagePipeline 统一消息处理
|
||||
- [x] 3.1 创建 `src/dialogue/message_pipeline.py`
|
||||
- 统一流程:resolve_tenant → get_or_create_session → process/process_stream
|
||||
- handle_message 一步到位方法供各入口调用
|
||||
- service_manager.get_pipeline() 注册
|
||||
- 各入口(WebSocket、HTTP、飞书 bot、飞书长连接)只负责协议适配
|
||||
- [ ] 3.2 重构 realtime_chat.py 使用 Pipeline
|
||||
- process_message 和 process_message_stream 委托给 Pipeline
|
||||
|
||||
Reference in New Issue
Block a user