Core Components: - PDFStorageService with Dify/OSS adapters - LLM12FieldsService with Nougat-first + dual-model + 3-layer JSON parsing - PromptBuilder for dynamic prompt assembly - MedicalLogicValidator with 5 rules + fault tolerance - EvidenceChainValidator for citation integrity - ConflictDetectionService for dual-model comparison Prompt Engineering: - System Prompt (6601 chars, Section-Aware strategy) - User Prompt template (PICOS context injection) - JSON Schema (12 fields constraints) - Cochrane standards (not loaded in MVP) Key Innovations: - 3-layer JSON parsing (JSON.parse + json-repair + code block extraction) - Promise.allSettled for dual-model fault tolerance - safeGetFieldValue for robust field extraction - Mixed CN/EN token calculation Integration Tests: - integration-test.ts (full test) - quick-test.ts (quick test) - cached-result-test.ts (fault tolerance test) Documentation Updates: - Development record (Day 2-3 summary) - Quality assurance strategy (full-text screening) - Development plan (progress update) - Module status (v1.1 update) - Technical debt (10 new items) Test Results: - JSON parsing success rate: 100% - Medical logic validation: 5/5 passed - Dual-model parallel processing: OK - Cost per PDF: CNY 0.10 Files: 238 changed, 14383 insertions(+), 32 deletions(-) Docs: docs/03-涓氬姟妯″潡/ASL-AI鏅鸿兘鏂囩尞/05-寮€鍙戣褰?2025-11-22_Day2-Day3_LLM鏈嶅姟涓庨獙璇佺郴缁熷紑鍙?md
LLM大模型网关
能力定位: 通用能力层核心能力
复用率: 71% (5个模块依赖)
优先级: P0(最高)⭐
状态: ❌ 待实现
📋 能力概述
LLM大模型网关是平台AI能力的核心中枢,负责:
- 统一管理所有LLM调用
- 根据用户版本动态切换模型
- 成本控制与限流
- Token计数与计费
🎯 核心价值
1. 商业模式技术基础 ⭐
专业版 → DeepSeek-V3(便宜,¥1/百万tokens)
高级版 → DeepSeek + Qwen3
旗舰版 → DeepSeek + Qwen3 + Qwen-Long + Claude
2. 成本控制
- 统一监控所有LLM API调用
- 超出配额自动限流
- 按版本计费
3. 统一接口
- 屏蔽不同LLM API的差异
- 统一的调用接口
📊 依赖模块
5个模块依赖(71%复用率):
- AIA - AI智能问答
- ASL - AI智能文献(双模型判断)
- PKB - 个人知识库(RAG问答)
- DC - 数据清洗(NER提取)
- RVW - 稿件审查(AI评估)
💡 核心功能
1. 模型选择
selectModel(userId: string, preferredModel?: string): string
// 根据用户版本和配额选择合适的模型
2. 统一调用
chat(params: {
userId: string;
modelType?: ModelType;
messages: Message[];
stream?: boolean;
}): Promise<ChatResponse>
3. 配额管理
checkQuota(userId: string): Promise<QuotaInfo>
// 检查用户剩余配额
4. Token计数
countTokens(text: string): number
// 使用tiktoken计算Token数
📂 文档结构
01-LLM大模型网关/
├── [AI对接] LLM网关快速上下文.md # ✅ 已完成
├── 03-CloseAI集成指南.md # ✅ 已完成 ⭐
├── 00-需求分析/
│ └── README.md
├── 01-设计文档/
│ ├── 01-详细设计.md # ⏳ Week 5创建
│ ├── 02-数据库设计.md # ⏳ Week 5创建
│ ├── 03-API设计.md # ⏳ Week 5创建
│ └── README.md
└── README.md # ✅ 当前文档
快速入门文档 ⭐
| 文档 | 说明 | 状态 |
|---|---|---|
| [AI对接] LLM网关快速上下文.md | 快速了解LLM网关设计 | ✅ 已完成 |
| 03-CloseAI集成指南.md | CloseAI(GPT-5+Claude-4.5)集成文档 ⭐ | ✅ 已完成 |
⚠️ 开发计划调整
原计划:Week 2完成LLM网关
调整: LLM网关完整实现推迟到Week 5 ✅
理由:
- 现有LLM调用已经work(DeepSeek、Qwen)
- CloseAI集成配置已完成,可直接使用
- ASL开发不阻塞,先用简单调用
- Week 5有多个模块实践后,再抽取统一网关更合理
当前可用(Week 3 ASL开发)✅
- ✅ DeepSeek API(直连)
- ✅ GPT-5-Pro API(CloseAI代理)
- ✅ Claude-4.5 API(CloseAI代理)
- ✅ Qwen API(DashScope)
- ✅ 4个模型的基础调用代码示例
Week 5完善(LLM网关统一)
- 统一调用接口
- 版本分级(专业版/高级版/旗舰版)
- 配额管理和限流
- Token计数和计费
- 使用记录和监控
🔗 相关文档
最后更新: 2025-11-06
维护人: 技术架构师