Skip to content

Commit 7586d59

Browse files
committed
final fixes
1 parent 8325caa commit 7586d59

6 files changed

Lines changed: 50 additions & 21 deletions

File tree

‎mindee/v2/client.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,13 @@ def _poll_for_rag_document(
295295
while retry_count < max_retries:
296296
if cancellation_token and cancellation_token.is_canceled:
297297
raise MindeeError("Request canceled through cancellation token.")
298-
299-
sleep(polling_options.delay_sec)
300298
logger.info("Poll attempt %s of %s", retry_count, max_retries)
301299

302300
response = self.get_rag_document(type(initial_response), document_id)
303301
retry_count += 1
304302

305303
if response.status == "Processing":
304+
sleep(polling_options.delay_sec)
306305
continue
307306
if response.status == "Failed":
308307
raise MindeeError("Job failed without an error payload.")

‎mindee/v2/client_options/base_annotation_parameters.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dataclasses import dataclass
33
from typing import Generic
44

5+
from mindee.parsing.common.string_dict import StringDict
56
from mindee.v2.parsing.base_rag_annotation_response import TypeRagAnnotationResponse
67

78

@@ -17,7 +18,7 @@ class BaseAnnotationParameters(ABC, Generic[TypeRagAnnotationResponse]):
1718
"""Response class for the annotation."""
1819

1920
@abstractmethod
20-
def get_request_parameters(self) -> dict[str, str]:
21+
def get_request_parameters(self) -> dict[str, str | StringDict]:
2122
"""Gets the request parameters for the upload request."""
2223

2324
def get_response_class(self) -> type[TypeRagAnnotationResponse]:

‎mindee/v2/mindee_http/mindee_api_v2.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def req_delete_extraction_rag_document(self, document_id: str) -> bool:
295295
timeout=self.request_timeout,
296296
follow_redirects=False,
297297
)
298-
return response.is_success()
298+
return response.is_success
299299

300300
@property
301301
def get_caller(self) -> Callable:

‎mindee/v2/product/extraction/rag_documents/params/rag_document_annotation_parameters.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from dataclasses import dataclass
2+
from dataclasses import asdict, dataclass
33
from typing import Any, ClassVar
44

55
from mindee.parsing.common.string_dict import StringDict
@@ -33,14 +33,14 @@ def __post_init__(self) -> None:
3333
elif isinstance(self.annotation, dict):
3434
self.annotation = RagAnnotation(self.annotation)
3535

36-
def get_request_parameters(self) -> dict[str, str]:
36+
def get_request_parameters(self) -> dict[str, str | StringDict]:
3737
"""Gets the request parameters for the upload request."""
3838
parameters: dict[str, Any] = {}
3939

4040
if self.status:
4141
parameters["status"] = self.status
4242

4343
if self.annotation is not None and isinstance(self.annotation, RagAnnotation):
44-
parameters["annotation"] = str(self.annotation)
44+
parameters["annotation"] = asdict(self.annotation)
4545

4646
return parameters

‎tests/v2/product/extraction/test_rag_documents.py‎

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from mindee.v2.product.extraction.rag_documents import (
66
ExtractionRagAnnotationResponse,
7+
RagAnnotation,
78
RagDocumentAnnotationParameters,
89
RagDocumentUploadParameters,
910
)
@@ -18,6 +19,14 @@
1819
)
1920
from tests.utils import V2_PRODUCT_PATH
2021

22+
expected_annotation = {
23+
"fields": {
24+
"simple": {"selected": False, "guidelines": None, "value": True},
25+
"list": {"selected": False, "guidelines": None, "items": []},
26+
"object": {"selected": False, "guidelines": None, "fields": {}},
27+
}
28+
}
29+
2130

2231
@pytest.mark.v2
2332
def test_post_parameters_must_init():
@@ -30,17 +39,41 @@ def test_post_parameters_must_init():
3039
@pytest.mark.v2
3140
def test_patch_parameters_must_init_from_dict():
3241
"""Should init PATCH parameters from an annotation dict."""
33-
annotation = {"fields": {"is_good": {"value": True}}}
42+
annotation = {
43+
"fields": {
44+
"simple": {"value": True},
45+
"list": {"items": []},
46+
"object": {"fields": {}},
47+
}
48+
}
3449
parameters = RagDocumentAnnotationParameters(
3550
document_id="invalid-document-id", status="Active", annotation=annotation
3651
)
3752
req_params = parameters.get_request_parameters()
3853
assert parameters.document_id == "invalid-document-id"
3954
assert req_params["status"] == "Active"
40-
assert (
41-
req_params["annotation"]
42-
== '{"fields":{"is_good":{"selected":false,"value":true}}}'
55+
assert req_params["annotation"] == expected_annotation
56+
57+
58+
@pytest.mark.v2
59+
def test_patch_parameters_must_init_from_object():
60+
"""Should init PATCH parameters from an annotation instance."""
61+
annotation = RagAnnotation(
62+
{
63+
"fields": {
64+
"simple": {"value": True},
65+
"list": {"items": []},
66+
"object": {"fields": {}},
67+
}
68+
}
4369
)
70+
parameters = RagDocumentAnnotationParameters(
71+
document_id="invalid-document-id", status="Active", annotation=annotation
72+
)
73+
req_params = parameters.get_request_parameters()
74+
assert parameters.document_id == "invalid-document-id"
75+
assert req_params["status"] == "Active"
76+
assert req_params["annotation"] == expected_annotation
4477

4578

4679
@pytest.mark.v2
@@ -49,15 +82,12 @@ def test_patch_parameters_must_init_from_string():
4982
parameters = RagDocumentAnnotationParameters(
5083
document_id="invalid-document-id",
5184
status="Active",
52-
annotation='{"fields": {"is_good": {"value": true}}}',
85+
annotation='{"fields": {"simple": {"value": true},"list": {"items": []},"object": {"fields": {}}}}',
5386
)
5487
req_params = parameters.get_request_parameters()
5588
assert parameters.document_id == "invalid-document-id"
5689
assert req_params["status"] == "Active"
57-
assert (
58-
req_params["annotation"]
59-
== '{"fields":{"is_good":{"selected":false,"value":true}}}'
60-
)
90+
assert req_params["annotation"] == expected_annotation
6191

6292

6393
@pytest.mark.v2

‎tests/v2/product/extraction/test_rag_documents_integration.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import pytest
44

55
from mindee import PathInput
6-
from mindee.error.mindee_error import MindeeError
76
from mindee.v2 import Client
7+
from mindee.v2.error import MindeeHTTPErrorV2
88
from mindee.v2.product.extraction.rag_documents import (
99
ExtractionRagAnnotationResponse,
1010
RagDocumentAnnotationParameters,
@@ -28,9 +28,8 @@ def test_rag_document_lifecycle_must_succeed():
2828
input_source = PathInput(
2929
V2_PRODUCT_PATH / "extraction" / "financial_document" / "default_sample.jpg"
3030
)
31-
parameters = RagDocumentUploadParameters(model_id=extraction_model_id)
32-
33-
post_response = client.upload_and_get_rag_document(input_source, parameters)
31+
post_parameters = RagDocumentUploadParameters(model_id=extraction_model_id)
32+
post_response = client.upload_and_get_rag_document(input_source, post_parameters)
3433
assert post_response is not None
3534

3635
post_annotation = post_response.annotation
@@ -101,5 +100,5 @@ def test_rag_document_lifecycle_must_succeed():
101100
delete_response = client.delete_extraction_rag_document(document_id)
102101
assert delete_response is True
103102

104-
with pytest.raises(MindeeError):
103+
with pytest.raises(MindeeHTTPErrorV2):
105104
client.get_rag_document(ExtractionRagAnnotationResponse, document_id)

0 commit comments

Comments
 (0)