Skip to content

Commit 212a490

Browse files
✨ add support for text_context on V2 POST (#373)
1 parent d600147 commit 212a490

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

mindee/input/inference_parameters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ class InferenceParameters:
2929
"""Options for polling. Set only if having timeout issues."""
3030
close_file: bool = True
3131
"""Whether to close the file after parsing."""
32+
text_context: Optional[str] = None
33+
"""Additional text context used by the model during inference. Not recommended, for specific use only."""

mindee/mindee_http/mindee_api_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def req_post_inference_enqueue(
9494
data["webhook_ids"] = params.webhook_ids
9595
if params.alias and len(params.alias):
9696
data["alias"] = params.alias
97+
if params.text_context and (params.text_context):
98+
data["text_context"] = params.text_context
9799

98100
if isinstance(input_source, LocalInputSource):
99101
files = {"file": input_source.read_contents(params.close_file)}

tests/v2/test_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def test_enqueue_and_parse_path_with_env_token(custom_base_url_client):
129129
)
130130
with pytest.raises(MindeeHTTPErrorV2):
131131
custom_base_url_client.enqueue_and_get_inference(
132-
input_doc, InferenceParameters("dummy-model")
132+
input_doc,
133+
InferenceParameters("dummy-model", text_context="ignore this message"),
133134
)
134135

135136

@@ -176,7 +177,7 @@ def test_error_handling(custom_base_url_client):
176177

177178

178179
@pytest.mark.v2
179-
def test_enqueue(custom_base_url_client):
180+
def test_queue_get(custom_base_url_client):
180181
response = custom_base_url_client.get_job("12345678-1234-1234-1234-123456789ABC")
181182
assert isinstance(response, JobResponse)
182183
assert isinstance(response.job, Job)

tests/v2/test_client_integration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_parse_file_filled_single_page_must_succeed(
131131
polygon=None,
132132
confidence=None,
133133
alias="py_integration_filled_single",
134+
text_context="this is an invoice.",
134135
)
135136

136137
response: InferenceResponse = v2_client.enqueue_and_get_inference(
@@ -172,7 +173,9 @@ def test_invalid_uuid_must_throw_error(v2_client: ClientV2) -> None:
172173
input_path: Path = FILE_TYPES_DIR / "pdf" / "blank_1.pdf"
173174

174175
input_source = PathInput(input_path)
175-
params = InferenceParameters(model_id="INVALID MODEL ID")
176+
params = InferenceParameters(
177+
model_id="INVALID MODEL ID", text_context="ignore this message"
178+
)
176179

177180
with pytest.raises(MindeeHTTPErrorV2) as exc_info:
178181
v2_client.enqueue_inference(input_source, params)

0 commit comments

Comments
 (0)