Files

58 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# iAOP-Template-Ti 一期 · LLM 场景层(LLM Scenarios)
对应 PRD 5.4 / 5.5 与 EPIC #11「[Template-Ti 一期] ④ LLM 报警解释 / 交接班 / NL 查询」:
复用 ④ LLM 网关(core/llm-gateway)与领域 RAG(core/rag-kb),针对 Ti 场景
配置 RAG 知识域与提示词模板,落地三个业务场景:
- **报警根因解释**(`alarm_explain`):高利害,启用幻觉校验信度阈值,低信度转人工;
- **交接班自动摘要**(`shift_handover`):生产概况 / 异常事项 / 安全注意事项;
- **自然语言查询驾驶舱**(`nl_query`):NL → 指标 / 查询意图。
验收(Issue #11):路由准确率 ≥ 96.5%、幻觉校验通过。
## 模块结构
```
templates/ti-cl4/llm-scenarios/
├── __init__.py 场景包入口(导出 TiScenarioRunner)
├── scenarios.py Ti 场景编排(三场景 + 演示知识文档集 + 组件装配)
├── config/
│ └── scenarios.template.yaml 场景配置资产(提示词绑定 / RAG 知识域 / 验收指标)
└── tests/
├── _bootstrap.py 测试引导(挂载 ti_scenarios / llm_gateway / rag_kb)
└── test_scenarios.py 场景端到端 + 路由准确率 + 幻觉校验测试
```
## 用法
```python
from ti_scenarios import TiScenarioRunner
runner = TiScenarioRunner()
# 1) 报警根因解释(高利害;低信度自动转人工)
r1 = runner.explain_alarm("炉温超上限报警怎么处理", confidence=0.95)
print(r1.answer) # 含 SOP 引用溯源
# 2) 交接班自动摘要
r2 = runner.generate_handover("甲班:生产平稳,炉温正常,无异常事项")
# 3) 自然语言查询驾驶舱
r3 = runner.query_cockpit("查询最近一小时的氯气流量趋势")
```
## 设计说明
- **内核零改动**:场景层只复用 `LLMGateway` / `PromptRegistry` / `SensitivityRouter` /
`RagKnowledgeBase`,换行业只改模板资产(prompts / router / kb / scenarios);
- **RAG 演示数据**:`DEMO_KB_DOCS` 内置工艺规范 / 异常处置 SOP / 交接班规范等
演示文档;接入真实客户数据时替换 `kb_loader`(`TiScenarioRunner(kb_loader=...)`);
- **验收自检**:`tests/test_scenarios.py::TestRouteAccuracy` 用 Ti 场景查询集
断言路由准确率 ≥ 96.5%;`TestScenariosE2E` 覆盖三场景端到端与幻觉校验。
## 运行测试
```bash
cd templates/ti-cl4/llm-scenarios/tests
python -m unittest discover -s . -p "test_*.py"
```