Commit Graph

7 Commits

Author SHA1 Message Date
fegger da37e91c86 Add CLI orchestration with confidence-gated XML output
- Refactors process_single into inner pipeline with guaranteed client close.

- Runs classifier -> OCR branch -> extraction -> review -> XML/sidecar.

- Uses review-corrected invoice when available.

- Confidence >= 0.75 produces XML; < 0.90 adds a human-review comment.

- Adds end-to-end CLI tests covering confidence bands, corrections, and batch mode.
2026-08-21 16:44:35 +02:00
fegger e2becd6219 Add review stage coverage and fix XML tax deduplication
- Reviewer now sends all pages to the review VLM alongside extracted JSON.

- XML builder deduplicates account.tax records by rate.

- XML builder raises on confidence below min_confidence_threshold.

- Adds fractional tax-rate support with stable external IDs.

- Adds expected_invoice.xml fixture, reviewer tests, and XML regression tests.
2026-08-21 16:44:25 +02:00
fegger 570c8585a0 Use shared prompt loader and structured OCR response in branches
- Replaces duplicated _load_prompt() helpers with shared load_prompt().

- Classifier raises cleanly when no renderable pages exist.

- scanned_print, handwritten, and mixed_unknown branches now force

  response_format=OcrResponse and parse via client.parse_json().

- Adds branch tests for multi-page OCR and corrected invoice handling.
2026-08-21 16:44:19 +02:00
fegger 081084816b Improve VLM client lifecycle, retries, metrics, and cache keys
- Adds abstract aclose() and shared load_prompt() helper to BaseVLMClient.

- OllamaClient now logs latency, tokens, and prompt hash per call.

- Retries cover HTTP 429 and 5xx in addition to network/timeout errors.

- Cache key now includes response_format and max_tokens.

- Warns when JSON schema generation falls back to plain 'json' format.

- Adds FakeVLMClient.aclose() and cache unit tests.
2026-08-21 16:44:14 +02:00
fegger 17e0496d2f Add OcrResponse schema and tighten invoice validation
- Adds OcrResponse Pydantic schema for OCR branch JSON output.

- Validates invoice_date and due_date as strict ISO 8601 calendar dates.

- Adds field descriptions to InvoiceLineItem for clearer VLM prompts.

- Expands schema tests for dates, decimal coercion, negatives, and line_items_sum().
2026-08-21 16:44:09 +02:00
fegger 2e81fa57bd Add uv.lock and bump mypy target to 3.12
Adds the uv lockfile generated from pyproject.toml and updates

tool.mypy.python_version to 3.12 so third-party stubs parse cleanly

while keeping runtime compatibility at Python 3.11.
2026-08-21 16:44:04 +02:00
fegger 7e706793fa Initial scaffold: local invoice OCR pipeline with Ollama, classifier branches, structured extraction, review, and Odoo XML export
- Add AGENTS.md and project-specific Zed skills (odoo-ocr-pipeline, odoo-xml-import, local-vlm-client).
- Implement Pydantic schemas for documents, invoices, review results, and VLM responses.
- Add unified BaseVLMClient with Ollama implementation and llama.cpp stub.
- Build pipeline stages: loader, classifier, digital_pdf/scanned_print/handwritten/mixed_unknown branches, extractor, reviewer, xml_builder.
- Add CLI entry point  with sidecar JSON and confidence-gated XML output.
- Include prompts for classifier, OCR, extraction, and review models.
- Add tests with FakeVLMClient; pytest, ruff, and mypy all pass.
2026-08-21 14:04:42 +02:00