c9f003e1b7
- 新增 backend/ocr_extractor.py: 两阶段提取流水线 (文档分析 + 字段提取) - 四种提取策略: 精确KV匹配/模糊KV匹配/正则模式/表格结构匹配 - agent/state.py: 新增 ocr_extraction_result 和 uploaded_file_path 字段 - agent/nodes.py: process_input() 中自动触发 OCR 提取钩子 - app.py: 文件上传时保留图片路径, 总结卡片中展示提取结果 - .env.example: 新增 OCR_USE_GPU / OCR_CONFIDENCE_THRESHOLD 配置项 - tests/test_ocr_extraction.py: 48 个单元测试全部通过
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""LangGraph JRXML 生成代理工作流的状态定义。"""
|
|
|
|
from typing import TypedDict, List
|
|
|
|
|
|
class AgentState(TypedDict, total=False):
|
|
# 核心工作流字段
|
|
conversation_history: List[dict]
|
|
current_jrxml: str
|
|
user_input: str
|
|
status: str
|
|
error_msg: str
|
|
natural_explanation: str
|
|
retry_count: int
|
|
user_modification_request: str
|
|
final_jrxml: str
|
|
stage: str
|
|
retrieved_context: str
|
|
|
|
# 需求1:智能上下文压缩
|
|
full_conversation_history: List[dict]
|
|
compressed_history: str
|
|
current_token_count: int
|
|
|
|
# 需求2:多会话持久化
|
|
session_id: str
|
|
session_name: str
|
|
created_at: str
|
|
updated_at: str
|
|
|
|
# 需求3:意图识别
|
|
intent: str
|
|
history_states: List[dict]
|
|
|
|
# 需求4:JRXML 版本历史(用于下载历史版本)
|
|
jrxml_versions: List[dict]
|
|
|
|
# 需求5:错误自增长(记录修正前的状态,供 validate 节点判断是否入知识库)
|
|
last_error_case: dict
|
|
|
|
# 需求6:失败上下文传递 — 重试耗尽后暂存失败信息,下次用户输入时自动注入
|
|
pending_failure_context: dict
|
|
|
|
# 需求7:OCR 单据字段精确提取结果
|
|
ocr_extraction_result: dict
|
|
uploaded_file_path: str
|