Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 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,22 @@ class InferenceActiveOptions:
"""Active options for the inference."""

raw_text: bool
"""Whether raw text extraction is active or not."""
polygon: bool
"""Whether polygon extraction is active or not."""
confidence: bool
"""Whether confidence scores are active or not."""
rag: bool
"""Whether RAG is active or not."""
text_context: bool
"""Whether text context is active or not."""
Comment thread
sebastianMindee marked this conversation as resolved.
Outdated

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
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
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
Loading