diff --git a/mindee/parsing/v2/inference_active_options.py b/mindee/parsing/v2/inference_active_options.py index 6a2d4656..2891173c 100644 --- a/mindee/parsing/v2/inference_active_options.py +++ b/mindee/parsing/v2/inference_active_options.py @@ -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 ( diff --git a/tests/data b/tests/data index 932b387e..f86f3eaf 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 932b387e48d909202d7b69ccf9230531dee3f036 +Subproject commit f86f3eaf540f0babeb3d4f1a458d764856a2170b diff --git a/tests/v2/input/test_local_response.py b/tests/v2/input/test_local_response.py index 82654579..e86d7877 100644 --- a/tests/v2/input/test_local_response.py +++ b/tests/v2/input/test_local_response.py @@ -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( diff --git a/tests/v2/parsing/test_inference_response.py b/tests/v2/parsing/test_inference_response.py index 9a5f9b9d..f494bb48 100644 --- a/tests/v2/parsing/test_inference_response.py +++ b/tests/v2/parsing/test_inference_response.py @@ -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 @@ -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 diff --git a/tests/v2/test_client.py b/tests/v2/test_client.py index 7ae18db4..15d4f583 100644 --- a/tests/v2/test_client.py +++ b/tests/v2/test_client.py @@ -1,4 +1,5 @@ import json +import os import pytest @@ -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() diff --git a/tests/v2/test_client_integration.py b/tests/v2/test_client_integration.py index 3330f7fb..3203cebf 100644 --- a/tests/v2/test_client_integration.py +++ b/tests/v2/test_client_integration.py @@ -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 @@ -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 @@ -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 @@ -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