Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ response = client.process_document_url(
)
```

Run thinking on the line items with `thinking` (`"light"` or `"deep"`; omit it to turn it off). Both `process_document` and `process_document_url` accept it, and `"deep"` takes longer than `"light"`. It only takes effect if thinking mode is enabled for your account.

```python
response = client.process_document(
file_path="/tmp/receipt.jpg",
thinking="light",
)
```

The response contains the extracted fields. A typical result looks like:

```python
Expand Down
38 changes: 38 additions & 0 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest
import responses

Expand Down Expand Up @@ -196,6 +198,42 @@ def test_process_document_url():
assert d == mock


@pytest.mark.parametrize("thinking", [None, "light", "deep"])
@responses.activate
def test_process_document_thinking(thinking):
client = Client(client_id="v", client_secret=None, username="o", api_key="c")
responses.add(
responses.POST,
f"{client.versioned_url}/partner/documents/",
json={"id": 1},
status=200,
)
client.process_document(file_path="tests/assets/receipt_public.jpg", thinking=thinking)
body = json.loads(responses.calls[0].request.body)
if thinking is None:
assert "thinking" not in body
else:
assert body["thinking"] == thinking


@pytest.mark.parametrize("thinking", [None, "light", "deep"])
@responses.activate
def test_process_document_url_thinking(thinking):
client = Client(client_id="v", client_secret=None, username="o", api_key="c")
responses.add(
responses.POST,
f"{client.versioned_url}/partner/documents/",
json={"id": 1},
status=200,
)
client.process_document_url(file_url="https://example.com/receipt.jpg", thinking=thinking)
body = json.loads(responses.calls[0].request.body)
if thinking is None:
assert "thinking" not in body
else:
assert body["thinking"] == thinking


@responses.activate
def test_get_documents():
mock = [
Expand Down
8 changes: 8 additions & 0 deletions veryfi/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def process_document(
file_path: str,
categories: Optional[List] = None,
delete_after_processing: bool = False,
thinking: Optional[str] = None,
**kwargs,
) -> Dict:
"""
Expand All @@ -105,6 +106,7 @@ def process_document(
:param file_path: Path on disk to a file to submit for data extraction
:param categories: List of categories Veryfi can use to categorize the document
:param delete_after_processing: Delete this document from Veryfi after data has been extracted
:param thinking: Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
:param kwargs: Additional body parameters
:return: Data extracted from the document
"""
Expand All @@ -119,6 +121,8 @@ def process_document(
"categories": categories,
"auto_delete": delete_after_processing,
}
if thinking is not None:
request_arguments["thinking"] = thinking
request_arguments.update(kwargs)
return self.client._request("POST", "/documents/", request_arguments)

Expand All @@ -131,6 +135,7 @@ def process_document_url(
external_id: Optional[str] = None,
max_pages_to_process: Optional[int] = None,
file_urls: Optional[List[str]] = None,
thinking: Optional[str] = None,
**kwargs,
) -> Dict:
"""Process Document from url and extract all the fields from it.
Expand All @@ -143,6 +148,7 @@ def process_document_url(
:param max_pages_to_process: When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
:param boost_mode: Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
:param external_id: Optional custom document identifier. Use this if you would like to assign your own ID to documents
:param thinking: Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
:param kwargs: Additional body parameters
:return: Data extracted from the document.
"""
Expand All @@ -156,6 +162,8 @@ def process_document_url(
"file_urls": file_urls,
"max_pages_to_process": max_pages_to_process,
}
if thinking is not None:
request_arguments["thinking"] = thinking
request_arguments.update(kwargs)
return self.client._request("POST", endpoint_name, request_arguments)

Expand Down
Loading