82 lines
2.6 KiB
Markdown
82 lines
2.6 KiB
Markdown
# V2 AI Platform Persistence, Prompt, Knowledge, and Audit Closure
|
|
|
|
日期:2026-06-22
|
|
|
|
## 本轮目标
|
|
|
|
本轮继续推进 `yuqei-ai-platform`,把前一轮只停留在内存演示的模型配置、知识库检索和 AI 调用审计,补成可持久化、可由 SDK 调用、可由 OpenAPI 描述的 MVP 闭环。
|
|
|
|
## 已完成
|
|
|
|
1. 仓库层抽象
|
|
- 新增 `AiPlatformRepository` 协议。
|
|
- 保留 `InMemoryAiPlatformRepository` 作为本地和测试默认实现。
|
|
- 新增 `SqlAlchemyAiPlatformRepository`,支持模型配置、Prompt 模板、知识文档、AI 调用审计落库。
|
|
|
|
2. 配置切换
|
|
- 新增 `AI_PLATFORM_REPOSITORY_BACKEND`。
|
|
- 可选值:`memory`、`sqlalchemy`。
|
|
- 新增 `AI_PLATFORM_DATABASE_AUTO_CREATE`,MVP 阶段可自动建表,后续正式部署再切到 Alembic migration。
|
|
|
|
3. Prompt 模板闭环
|
|
- 新增 `PromptTemplateCreate`、`PromptTemplate`。
|
|
- 新增接口:
|
|
- `GET /api/v1/prompt-templates`
|
|
- `POST /api/v1/prompt-templates`
|
|
- 法律问答审计会记录当前 `legal_qa.default` 的 `prompt_template_id`。
|
|
|
|
4. SDK 能力扩展
|
|
- `yuqei-ai-sdk-python` 新增:
|
|
- `list_model_configs`
|
|
- `upsert_model_config`
|
|
- `list_prompt_templates`
|
|
- `upsert_prompt_template`
|
|
- `add_knowledge_document`
|
|
- `search_knowledge_documents`
|
|
- `list_ai_run_audits`
|
|
|
|
5. OpenAPI 契约同步
|
|
- 新增 Prompt 模板路径和 schema。
|
|
- 修正 AI 审计列表参数为当前实现使用的 `limit`。
|
|
- 补齐健康检查响应字段。
|
|
|
|
## 验证结果
|
|
|
|
已通过:
|
|
|
|
```powershell
|
|
python -m pytest
|
|
```
|
|
|
|
结果:
|
|
|
|
```text
|
|
16 passed
|
|
```
|
|
|
|
新增覆盖:
|
|
|
|
- Prompt 模板可热更新并列表读取。
|
|
- SQLite 持久化仓库可跨 repository 实例读取模型配置、Prompt、知识文档和审计记录。
|
|
- SDK 覆盖 AI 中台管理类接口。
|
|
- 法律问答审计可关联 Prompt 模板。
|
|
|
|
## 当前边界
|
|
|
|
本轮还没有做:
|
|
|
|
- Alembic migration 文件。
|
|
- PostgreSQL 真库部署演练。
|
|
- 向量检索和混合排序。
|
|
- 真实模型 provider 调用。
|
|
- token、费用、错误重试等更完整的调用审计字段。
|
|
|
|
## 下一轮建议
|
|
|
|
下一轮进入 AI Platform 的真实运行能力:
|
|
|
|
1. 建立 Alembic migration,并把自动建表降级为本地开发能力。
|
|
2. 加入 provider adapter 抽象,先实现 OpenAI-compatible / DeepSeek-compatible 调用。
|
|
3. 把法律问答从规则型回答升级为:知识检索 -> Prompt 模板渲染 -> Provider 调用 -> 引用与审计落库。
|
|
4. 为知识库增加导入批次、切分结果、检索命中分数和来源定位。
|