Skip to content

Commit 90109cf

Browse files
♻️ add missing text_context active option return param (#376)
1 parent 95352c5 commit 90109cf

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

mindee/parsing/v2/inference_active_options.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,37 @@ class InferenceActiveOptions:
55
"""Active options for the inference."""
66

77
raw_text: bool
8+
"""
9+
Whether the Raw Text feature was activated.
10+
When this feature is activated, the raw text extracted from the document is returned in the result.
11+
"""
812
polygon: bool
13+
"""
14+
Whether the polygon feature was activated.
15+
When this feature is activated, the bounding-box polygon(s) for each field is returned in the result.
16+
"""
917
confidence: bool
18+
"""
19+
Whether the confidence feature was activated.
20+
When this feature is activated, a confidence score for each field is returned in the result.
21+
"""
1022
rag: bool
23+
"""
24+
Whether the Retrieval-Augmented Generation feature was activated.
25+
When this feature is activated, the RAG pipeline is used to increase result accuracy.
26+
"""
27+
text_context: bool
28+
"""
29+
Whether the text context feature was activated.
30+
When this feature is activated, the provided context is used to improve the accuracy of the inference.
31+
"""
1132

1233
def __init__(self, raw_response: StringDict):
1334
self.raw_text = raw_response["raw_text"]
1435
self.polygon = raw_response["polygon"]
1536
self.confidence = raw_response["confidence"]
1637
self.rag = raw_response["rag"]
38+
self.text_context = raw_response["text_context"]
1739

1840
def __str__(self) -> str:
1941
return (

tests/v2/input/test_local_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def file_path() -> Path:
1414

1515
def _assert_local_response(local_response):
1616
fake_hmac_signing = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"
17-
signature = "b9c2dfc67c2ba457603dd9880d45f089ae79b95bf6389b4a4387ef255c924fe7"
17+
signature = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be"
1818

1919
assert local_response._file is not None
2020
assert not local_response.is_valid_hmac_signature(

tests/v2/parsing/test_inference_response.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from mindee import InferenceResponse
8+
from mindee.parsing.v2 import InferenceActiveOptions
89
from mindee.parsing.v2.field import FieldConfidence, ListField, ObjectField, SimpleField
910
from mindee.parsing.v2.field.inference_fields import InferenceFields
1011
from mindee.parsing.v2.inference import Inference
@@ -298,3 +299,20 @@ def test_field_locations_and_confidence() -> None:
298299
assert date_field.confidence > FieldConfidence.LOW
299300
assert date_field.confidence <= FieldConfidence.HIGH
300301
assert date_field.confidence < FieldConfidence.HIGH
302+
303+
304+
@pytest.mark.v2
305+
def test_text_context_field_is_false() -> None:
306+
json_sample, _ = _get_product_samples("financial_document", "complete")
307+
inference_result = InferenceResponse(json_sample)
308+
assert isinstance(inference_result.inference.active_options, InferenceActiveOptions)
309+
assert inference_result.inference.active_options.text_context is False
310+
311+
312+
@pytest.mark.v2
313+
def test_text_context_field_is_true() -> None:
314+
with open(V2_DATA_DIR / "inference" / "text_context_enabled.json", "r") as file:
315+
json_sample = json.load(file)
316+
inference_result = InferenceResponse(json_sample)
317+
assert isinstance(inference_result.inference.active_options, InferenceActiveOptions)
318+
assert inference_result.inference.active_options.text_context is True

tests/v2/test_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23

34
import pytest
45

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

102103

104+
@pytest.fixture
105+
def env_no_key(monkeypatch):
106+
if os.getenv("MINDEE_V2_API_KEY"):
107+
monkeypatch.delenv("MINDEE_V2_API_KEY")
108+
109+
103110
@pytest.mark.v2
104-
def test_parse_path_without_token():
111+
def test_parse_path_without_token(env_no_key):
105112
with pytest.raises(MindeeApiV2Error):
106113
ClientV2()
107114

tests/v2/test_client_integration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from mindee import ClientV2, InferenceParameters, PathInput, UrlInputSource
77
from mindee.error.mindee_http_error_v2 import MindeeHTTPErrorV2
8+
from mindee.parsing.v2 import InferenceActiveOptions
89
from mindee.parsing.v2.inference_response import InferenceResponse
910
from tests.utils import FILE_TYPES_DIR, V2_PRODUCT_DATA_DIR
1011

@@ -59,11 +60,13 @@ def test_parse_file_empty_multiple_pages_must_succeed(
5960
assert response.inference.model is not None
6061
assert response.inference.model.id == findoc_model_id
6162

63+
assert isinstance(response.inference.active_options, InferenceActiveOptions)
6264
assert response.inference.active_options is not None
6365
assert response.inference.active_options.rag is False
6466
assert response.inference.active_options.raw_text is True
6567
assert response.inference.active_options.polygon is False
6668
assert response.inference.active_options.confidence is False
69+
assert response.inference.active_options.text_context is False
6770

6871
assert response.inference.result is not None
6972

@@ -103,11 +106,13 @@ def test_parse_file_empty_single_page_options_must_succeed(
103106
assert response.inference.file.name == "blank_1.pdf"
104107
assert response.inference.file.page_count == 1
105108

109+
assert isinstance(response.inference.active_options, InferenceActiveOptions)
106110
assert response.inference.active_options is not None
107111
assert response.inference.active_options.rag is True
108112
assert response.inference.active_options.raw_text is True
109113
assert response.inference.active_options.polygon is True
110114
assert response.inference.active_options.confidence is True
115+
assert response.inference.active_options.text_context is False
111116

112117
assert response.inference.result is not None
113118

@@ -148,11 +153,13 @@ def test_parse_file_filled_single_page_must_succeed(
148153
assert response.inference.model is not None
149154
assert response.inference.model.id == findoc_model_id
150155

156+
assert isinstance(response.inference.active_options, InferenceActiveOptions)
151157
assert response.inference.active_options is not None
152158
assert response.inference.active_options.rag is False
153159
assert response.inference.active_options.raw_text is False
154160
assert response.inference.active_options.polygon is False
155161
assert response.inference.active_options.confidence is False
162+
assert response.inference.active_options.text_context is True
156163

157164
assert response.inference.result.raw_text is None
158165

0 commit comments

Comments
 (0)