feat(server): 扩展文档智能识别服务,新增Azure Document Intelligence集成和测试用例
This commit is contained in:
@@ -64,3 +64,55 @@ def test_document_intelligence_service_uses_vlm_result_when_preview_available(mo
|
||||
assert insight.document_type == "taxi_receipt"
|
||||
assert insight.classification_source == "llm_vision"
|
||||
assert calls[0] == ("vlm",)
|
||||
|
||||
|
||||
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_uses_vlm_fields_to_correct_amount(monkeypatch) -> None:
|
||||
def fake_complete(self, messages, *, slot_priority=("main", "backup"), max_tokens=500, temperature=0.2):
|
||||
if slot_priority == ("vlm",):
|
||||
return json.dumps(
|
||||
{
|
||||
"document_type": "taxi_receipt",
|
||||
"scene_code": "transport",
|
||||
"scene_label": "交通票据",
|
||||
"expense_type": "transport",
|
||||
"confidence": 0.89,
|
||||
"evidence": ["图片主体为滴滴行程单,金额区域显示 13.4 元"],
|
||||
"fields": [
|
||||
{"key": "amount", "label": "金额", "value": "13.4"},
|
||||
{"key": "merchant_name", "label": "商户", "value": "滴滴出行"},
|
||||
],
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(RuntimeChatService, "complete", fake_complete)
|
||||
|
||||
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 == "13.4元" for field in insight.fields)
|
||||
assert any("大模型复核结果修正" in warning for warning in insight.warnings)
|
||||
|
||||
Reference in New Issue
Block a user