report_generation/README.md
xxy aa98ea2623 @
Initial commit

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
2026-06-05 18:45:29 +08:00

53 lines
2.6 KiB
Markdown
Raw 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.

# 报告生成服务(独立抽取版)
`eval_report` 中抽取出的「后评价报告核心生成」链路,作为独立 FastAPI 服务运行。
保留原有的证据装配(要素表 + Milvus 向量检索)、分章 LLM 生成、表格修复、报告合并与 SSE 流式进度,
连接与原项目相同的 MySQL / Milvus / LLM 服务。
## 范围
- 包含异步分章生成任务、进度查询、结果获取、SSE 实时事件、章节重试、任务取消。
- 不含:鉴权、知识库 worker、模板/范文管理、Word(docx) 导出(这些仍在原 `eval_report` 中)。
## 目录结构
```
report_generation/
main.py FastAPI 入口
config.py 配置DB / LLM / Embedding / Milvus / DOC_PAT
database/ SQLAlchemy 引擎、Session、ORM 模型、建表
schemas/ Pydantic 模型
services/ 报告生成核心逻辑(含瘦身版 kb_service / docx_export_service / project_service
function/vector_store.py Milvus 向量库封装
prompts/report_generation/ 提示词模板与章节合同
routers/report.py 报告生成 HTTP 端点
```
## 快速开始
```bash
pip install -r requirements.txt
cp .env.example .env # 按需填写 DATABASE_URL / LLM_* / EMBEDDING_* / MILVUS_DB_URL
uvicorn main:app --reload
```
启动后访问 `http://127.0.0.1:8099/docs` 查看接口文档,`/health` 做健康检查。
## 主要接口(前缀 `/api/v1/write`
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/projects/{project_id}/generate-sections` | 预览模板章节提示词清单 |
| POST | `/projects/{project_id}/generate-report-job` | 创建分章异步报告生成任务 |
| GET | `/projects/{project_id}/generate-report-job/{job_id}` | 查询任务进度 |
| GET | `/projects/{project_id}/generate-report-job/{job_id}/result` | 获取任务结果 |
| GET | `/projects/{project_id}/generate-report-job/{job_id}/events` | 订阅实时事件SSE |
| POST | `/projects/{project_id}/generate-report-job/{job_id}/retry-chapter` | 重试指定章节 |
| POST | `/projects/{project_id}/generate-report-job/{job_id}/cancel` | 取消任务 |
## 依赖的外部数据
报告生成依赖原库中已有的项目数据:`projects``element_tables` / `element_cells`(要素表)、
`report_templates` / `report_template_sections`(模板章节)、可选的 `report_section_references`(参考范文),
以及 Milvus 中按项目 UUID 写入的文档向量。请确保新服务连接到已包含这些数据的 MySQL 与 Milvus。