feat: layered precise generation for A4 report images

3-phase pipeline to solve LLM prompt overflow from too many OCR elements:
Phase 1 (generate_skeleton): compressed layout schema → skeleton JRXML
Phase 2 (refine_layout): sampled coordinates → pixel-level position tuning
Phase 3 (map_fields): OCR field names → replace $F{field_N} placeholders

Only triggered when layout_schema.total_rows > 0 on initial_generation intent.
Text requests and all other intents are unaffected (zero behavior change).
This commit is contained in:
2026-05-21 08:34:32 +08:00
parent 9bb011e429
commit 43a0542a11
14 changed files with 882 additions and 81 deletions
+8 -6
View File
@@ -12,6 +12,7 @@
- **聊天粘贴/拖拽**:支持直接在对话框中 Ctrl+V 粘贴或拖拽文件(图片/PDF/Excel/Word
- **单据OCR识别**:上传报表单据图片后自动提取所有字段(4策略优先级 + 置信度评分)
- **批注检测**:识别手写单据上的圈选和箭头标记,自动定位用户要修改的字段
- **分层精确生成**:A4 报表图片先提取布局 schema,再分 3 阶段(骨架→精调→字段映射)生成,避免 OCR 元素过多导致 prompt 溢出
- **下载**:导出已验证的、可供 JasperReports 使用的 JRXML 文件
## 架构
@@ -21,7 +22,7 @@ Streamlit 界面 (app.py)
|
LangGraph 代理 (agent/)
|-- retrieve (Chroma/embeddings)
|-- generate (LLM)
|-- generate / generate_skeleton → refine_layout → map_fields (分层生成)
|-- validate (FastAPI service)
|-- explain + correct (auto-fix loop)
|-- modify (multi-turn edits)
@@ -111,9 +112,9 @@ pytest tests/ -v
jrxml-agent/
app.py Streamlit 聊天界面(多模态输入)
agent/
state.py AgentState 定义(26 字段)
nodes.py 图节点(generate, validate, modify 等,15 节点)
graph.py LangGraph 状态机
state.py AgentState 定义(28 字段)
nodes.py 图节点(generate, generate_skeleton, refine_layout 等,18 节点)
graph.py LangGraph 状态机(含分层生成路由)
backend/
llm.py LLM 工厂(Anthropic SDK / OpenAI / Ollama
logger.py 集中日志模块(JSON + trace_id
@@ -122,13 +123,13 @@ jrxml-agent/
rag_adapter.py RAG 语义搜索适配器
error_kb.py 错误自增长知识库
file_parser.py 文件解析器(PDF/DOCX/XLSX/XLS/DOC/图片/文本)
layout_analyzer.py A4 模板布局分析
layout_analyzer.py A4 模板布局分析(含布局 schema 提取)
ocr_extractor.py OCR 字段精确提取(4 策略 + 置信度)
annotation_detector.py 批注检测(圈选 + 箭头 + OCR 关联)
session.py 会话持久化 CRUD
prompts/
loader.py Prompt 加载器(热重载)
*.md 7 个 Prompt 模板文件
*.md 10 个 Prompt 模板文件
validation_service/
main.py FastAPI 验证服务器
validate.bat Windows 启动器
@@ -147,6 +148,7 @@ jrxml-agent/
test_ocr_extraction.py OCR 字段提取单元测试
test_annotation_detector.py 批注检测测试
test_file_parser_formats.py 多格式解析测试
test_layered_generation.py 分层生成测试
requirements.txt
.env.example
README.md