Files
X-Financial/server/tests/test_document_intelligence.py
caoxiaozhu 68f663f2f4 feat: 重构知识库系统,移除Hermes集成,增强RAG和同步功能
主要变更:
- 移除Hermes智能体及相关回调服务
- 新增知识库RAG、同步、调度、规范化和索引任务服务
- 重构orchestrator服务,增强运行时聊天功能
- 更新前端聊天、政策制度、设置等页面样式和逻辑
- 更新expense_claims和document_intelligence服务
- 删除llm_wiki相关服务和测试文件
- 更新docker-compose配置和启动脚本
2026-05-17 08:38:41 +00:00

73 lines
2.8 KiB
Python

from __future__ import annotations
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
from app.services.document_intelligence import DocumentIntelligenceService, build_document_insight
def test_build_document_insight_prefers_transport_for_didi_text_with_hotel_noise() -> None:
insight = build_document_insight(
filename="didi-trip.png",
summary="滴滴出行行程单",
text="滴滴出行电子发票 订单号 12345678 上车点 深圳湾 下车点 后海 全季酒店 里程 12.4 公里 金额 48 元",
)
assert insight.document_type == "taxi_receipt"
assert insight.document_type_label == "出租车/网约车票据"
assert insight.scene_code == "transport"
assert any(field.label == "金额" and field.value == "48元" for field in insight.fields)
def test_document_intelligence_service_uses_rule_result_when_preview_available() -> None:
engine = create_engine(
"sqlite+pysqlite:///:memory:",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
session = sessionmaker(bind=engine, autoflush=False, autocommit=False)()
try:
insight = DocumentIntelligenceService(session).build_document_insight(
filename="mixed-noise.png",
summary="OCR 混入酒店名称",
text="全季酒店 滴滴出行 订单号 12345678 上车 下车 金额 52 元",
preview_data_url="data:image/png;base64,ZmFrZQ==",
)
finally:
session.close()
assert insight.document_type == "taxi_receipt"
assert insight.classification_source == "rule"
def test_document_intelligence_extracts_larger_decimal_amount_from_multiple_candidates() -> None:
insight = build_document_insight(
filename="taxi-amount.png",
summary="滴滴出行电子行程单",
text="滴滴出行 支付金额 1 元,实付 13.4 元,订单号 12345678",
)
assert any(field.label == "金额" and field.value == "13.4元" for field in insight.fields)
def test_document_intelligence_service_keeps_rule_fields_without_model_correction() -> None:
engine = create_engine(
"sqlite+pysqlite:///:memory:",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
session = sessionmaker(bind=engine, autoflush=False, autocommit=False)()
try:
insight = DocumentIntelligenceService(session).build_document_insight(
filename="didi-corrected.png",
summary="滴滴出行电子行程单",
text="滴滴出行 支付金额 1 元 订单号 12345678",
preview_data_url="data:image/png;base64,ZmFrZQ==",
)
finally:
session.close()
assert any(field.label == "金额" and field.value == "1元" for field in insight.fields)
assert insight.warnings == ()