72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
from datetime import date
|
|
|
|
import httpx
|
|
|
|
from orc_renaming.models import DocumentScope, DocumentType, ExtractionResult
|
|
from orc_renaming.ollama import OllamaAnalyzer, merge_results
|
|
|
|
|
|
def test_stammdaten_override_llm() -> None:
|
|
rules = ExtractionResult(
|
|
document_type=DocumentType.INVOICE,
|
|
scope=DocumentScope.PROPERTY,
|
|
document_date=date(2026, 7, 18),
|
|
company="Kanonische-Firma",
|
|
property_id="WH1",
|
|
confidence=0.93,
|
|
evidence=["Stammdatentreffer"],
|
|
)
|
|
llm = ExtractionResult(
|
|
document_type=DocumentType.CORRESPONDENCE,
|
|
scope=DocumentScope.PRIVATE,
|
|
document_date=date(2026, 7, 17),
|
|
company="Halluzinierte Firma",
|
|
topic="Rechnung",
|
|
confidence=0.99,
|
|
evidence=["Modelltreffer"],
|
|
source="ollama",
|
|
)
|
|
|
|
result = merge_results(rules, llm)
|
|
assert result.document_type == DocumentType.INVOICE
|
|
assert result.scope == DocumentScope.PROPERTY
|
|
assert result.document_date == date(2026, 7, 18)
|
|
assert result.company == "Kanonische-Firma"
|
|
assert result.property_id == "WH1"
|
|
assert result.source == "rules+ollama"
|
|
|
|
|
|
def test_ollama_structured_response(config) -> None:
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
assert request.url.path == "/api/chat"
|
|
body = request.read().decode()
|
|
assert '"format":' in body
|
|
assert '"temperature":0' in body
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"message": {
|
|
"content": (
|
|
'{"document_type":"invoice","scope":"property",'
|
|
'"document_date":"2026-07-18","company":"Firma",'
|
|
'"property_id":"WH1","topic":null,"confidence":0.94,'
|
|
'"evidence":["Rechnung"]}'
|
|
)
|
|
}
|
|
},
|
|
)
|
|
|
|
analyzer = OllamaAnalyzer(config)
|
|
analyzer.client.close()
|
|
analyzer.client = httpx.Client(
|
|
base_url="http://ollama.test",
|
|
transport=httpx.MockTransport(handler),
|
|
)
|
|
result = analyzer.analyze("Rechnung für Musterstraße 12")
|
|
analyzer.close()
|
|
|
|
assert result.document_type == DocumentType.INVOICE
|
|
assert result.property_id == "WH1"
|
|
assert result.document_date == date(2026, 7, 18)
|
|
|