Skip to content
Merged
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
22 changes: 22 additions & 0 deletions mindee/parsing/v2/inference_active_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@ class InferenceActiveOptions:
"""Active options for the inference."""

raw_text: bool
"""
Whether the Raw Text feature was activated.
When this feature is activated, the raw text extracted from the document is returned in the result.
"""
polygon: bool
"""
Whether the polygon feature was activated.
When this feature is activated, the bounding-box polygon(s) for each field is returned in the result.
"""
confidence: bool
"""
Whether the confidence feature was activated.
When this feature is activated, a confidence score for each field is returned in the result.
"""
rag: bool
"""
Whether the Retrieval-Augmented Generation feature was activated.
When this feature is activated, the RAG pipeline is used to increase result accuracy.
"""
text_context: bool
"""
Whether the text context feature was activated.
When this feature is activated, the provided context is used to improve the accuracy of the inference.
"""

def __init__(self, raw_response: StringDict):
self.raw_text = raw_response["raw_text"]
self.polygon = raw_response["polygon"]
self.confidence = raw_response["confidence"]
self.rag = raw_response["rag"]
self.text_context = raw_response["text_context"]

def __str__(self) -> str:
return (
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/input/test_local_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def file_path() -> Path:

def _assert_local_response(local_response):
fake_hmac_signing = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"
signature = "b9c2dfc67c2ba457603dd9880d45f089ae79b95bf6389b4a4387ef255c924fe7"
signature = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be"

assert local_response._file is not None
assert not local_response.is_valid_hmac_signature(
Expand Down
18 changes: 18 additions & 0 deletions tests/v2/parsing/test_inference_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from mindee import InferenceResponse
from mindee.parsing.v2 import InferenceActiveOptions
from mindee.parsing.v2.field import FieldConfidence, ListField, ObjectField, SimpleField
from mindee.parsing.v2.field.inference_fields import InferenceFields
from mindee.parsing.v2.inference import Inference
Expand Down Expand Up @@ -298,3 +299,20 @@ def test_field_locations_and_confidence() -> None:
assert date_field.confidence > FieldConfidence.LOW
assert date_field.confidence <= FieldConfidence.HIGH
assert date_field.confidence < FieldConfidence.HIGH


@pytest.mark.v2
def test_text_context_field_is_false() -> None:
json_sample, _ = _get_product_samples("financial_document", "complete")
inference_result = InferenceResponse(json_sample)
assert isinstance(inference_result.inference.active_options, InferenceActiveOptions)
assert inference_result.inference.active_options.text_context is False


@pytest.mark.v2
def test_text_context_field_is_true() -> None:
with open(V2_DATA_DIR / "inference" / "text_context_enabled.json", "r") as file:
json_sample = json.load(file)
inference_result = InferenceResponse(json_sample)
assert isinstance(inference_result.inference.active_options, InferenceActiveOptions)
assert inference_result.inference.active_options.text_context is True
9 changes: 8 additions & 1 deletion tests/v2/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

import pytest

Expand Down Expand Up @@ -100,8 +101,14 @@ def _fake_ok_get_inference(*args, **kwargs):
return ClientV2("dummy")


@pytest.fixture
def env_no_key(monkeypatch):
if os.getenv("MINDEE_V2_API_KEY"):
monkeypatch.delenv("MINDEE_V2_API_KEY")


@pytest.mark.v2
def test_parse_path_without_token():
def test_parse_path_without_token(env_no_key):
with pytest.raises(MindeeApiV2Error):
ClientV2()

Expand Down
7 changes: 7 additions & 0 deletions tests/v2/test_client_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from mindee import ClientV2, InferenceParameters, PathInput, UrlInputSource
from mindee.error.mindee_http_error_v2 import MindeeHTTPErrorV2
from mindee.parsing.v2 import InferenceActiveOptions
from mindee.parsing.v2.inference_response import InferenceResponse
from tests.utils import FILE_TYPES_DIR, V2_PRODUCT_DATA_DIR

Expand Down Expand Up @@ -59,11 +60,13 @@ def test_parse_file_empty_multiple_pages_must_succeed(
assert response.inference.model is not None
assert response.inference.model.id == findoc_model_id

assert isinstance(response.inference.active_options, InferenceActiveOptions)
assert response.inference.active_options is not None
assert response.inference.active_options.rag is False
assert response.inference.active_options.raw_text is True
assert response.inference.active_options.polygon is False
assert response.inference.active_options.confidence is False
assert response.inference.active_options.text_context is False

assert response.inference.result is not None

Expand Down Expand Up @@ -103,11 +106,13 @@ def test_parse_file_empty_single_page_options_must_succeed(
assert response.inference.file.name == "blank_1.pdf"
assert response.inference.file.page_count == 1

assert isinstance(response.inference.active_options, InferenceActiveOptions)
assert response.inference.active_options is not None
assert response.inference.active_options.rag is True
assert response.inference.active_options.raw_text is True
assert response.inference.active_options.polygon is True
assert response.inference.active_options.confidence is True
assert response.inference.active_options.text_context is False

assert response.inference.result is not None

Expand Down Expand Up @@ -148,11 +153,13 @@ def test_parse_file_filled_single_page_must_succeed(
assert response.inference.model is not None
assert response.inference.model.id == findoc_model_id

assert isinstance(response.inference.active_options, InferenceActiveOptions)
assert response.inference.active_options is not None
assert response.inference.active_options.rag is False
assert response.inference.active_options.raw_text is False
assert response.inference.active_options.polygon is False
assert response.inference.active_options.confidence is False
assert response.inference.active_options.text_context is True

assert response.inference.result.raw_text is None

Expand Down