mirror of
https://github.com/run-llama/template-workflow-invoice-extraction.git
synced 2026-07-01 21:24:00 -04:00
02a0bc94f0
- extract-reconcile-invoice: index_contract.py called files.get_file / files.read_file_content / files.upload_file (v1 SDK surface removed in v2), breaking every Upload Contract click. Switched to files.list + files.get + files.create. - Added test_index_contract_workflow and test_metadata_workflow to exercise the full v2 surface (files.list, files.get, pipelines.upsert, pipelines.documents.upsert, configurations.retrieve). - document-parsing and invoice-extraction had only placeholder tests — wired up llama-cloud-fake and added parametrized tests covering every tier/mode. invoice-extraction's test drives the HIL step. - Bumped requires-python to >=3.12 on both (fake floor).
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import pytest
|
|
from invoice_extraction.workflow import (
|
|
FeedbackRequiredEvent,
|
|
HumanFeedbackEvent,
|
|
workflow,
|
|
)
|
|
from llama_cloud_fake import FakeLlamaCloudServer
|
|
|
|
|
|
@pytest.mark.parametrize("extraction_mode", ["base", "advanced", "premium"])
|
|
async def test_invoice_extraction_workflow(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
fake: FakeLlamaCloudServer,
|
|
extraction_mode: str,
|
|
) -> None:
|
|
"""Exercise files.create + extract.create + wait_for_completion via the fake,
|
|
then approve through the human-in-the-loop step."""
|
|
monkeypatch.setenv("LLAMA_CLOUD_API_KEY", "fake-api-key")
|
|
handler = workflow.run(
|
|
path="tests/files/test.pdf",
|
|
extraction_mode=extraction_mode,
|
|
)
|
|
feedback_event: FeedbackRequiredEvent | None = None
|
|
async for ev in handler.stream_events():
|
|
if isinstance(ev, FeedbackRequiredEvent):
|
|
feedback_event = ev
|
|
handler.ctx.send_event(HumanFeedbackEvent(approved=True))
|
|
break
|
|
result = await handler
|
|
assert feedback_event is not None
|
|
assert isinstance(feedback_event.extraction_result, str)
|
|
assert result == feedback_event.extraction_result
|