Skip to content

Commit 509e090

Browse files
add public url parameter to workflows
1 parent cc1e30b commit 509e090

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

mindee/client.py

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

55
from mindee.error.mindee_error import MindeeClientError, MindeeError
66
from mindee.error.mindee_http_error import handle_error
7+
from mindee.input import WorkflowOptions
78
from mindee.input.local_response import LocalResponse
89
from mindee.input.page_options import PageOptions
910
from mindee.input.sources import (
@@ -25,7 +26,6 @@
2526
from mindee.mindee_http.workflow_endpoint import WorkflowEndpoint
2627
from mindee.mindee_http.workflow_settings import WorkflowSettings
2728
from mindee.parsing.common.async_predict_response import AsyncPredictResponse
28-
from mindee.parsing.common.execution_priority import ExecutionPriority
2929
from mindee.parsing.common.feedback_response import FeedbackResponse
3030
from mindee.parsing.common.inference import Inference
3131
from mindee.parsing.common.predict_response import PredictResponse
@@ -239,10 +239,8 @@ def execute_workflow(
239239
self,
240240
input_source: Union[LocalInputSource, UrlInputSource],
241241
workflow_id: str,
242+
options: Optional[WorkflowOptions] = None,
242243
page_options: Optional[PageOptions] = None,
243-
alias: Optional[str] = None,
244-
priority: Optional[ExecutionPriority] = None,
245-
full_text: bool = False,
246244
) -> WorkflowResponse:
247245
"""
248246
Send the document to an asynchronous endpoint and return its ID in the queue.
@@ -252,9 +250,7 @@ def execute_workflow(
252250
:param workflow_id: ID of the workflow.
253251
:param page_options: If set, remove pages from the document as specified. This is done before sending the file\
254252
to the server. It is useful to avoid page limitations.
255-
:param alias: Optional alias for the document.
256-
:param priority: Optional priority for the document.
257-
:param full_text: Whether to include the full OCR text response in compatible APIs.
253+
:param options: Options for the workflow.
258254
:return:
259255
"""
260256
if isinstance(input_source, LocalInputSource):
@@ -267,9 +263,12 @@ def execute_workflow(
267263

268264
logger.debug("Sending document to workflow: %s", workflow_id)
269265

270-
return self._send_to_workflow(
271-
GeneratedV1, input_source, workflow_id, alias, priority, full_text
272-
)
266+
if not options:
267+
options = WorkflowOptions(
268+
alias=None, priority=None, full_text=False, public_url=None
269+
)
270+
271+
return self._send_to_workflow(GeneratedV1, input_source, workflow_id, options)
273272

274273
def _validate_async_params(
275274
self, initial_delay_sec: float, delay_sec: float, max_retries: int
@@ -484,9 +483,7 @@ def _send_to_workflow(
484483
product_class: Type[Inference],
485484
input_source: Union[LocalInputSource, UrlInputSource],
486485
workflow_id: str,
487-
alias: Optional[str] = None,
488-
priority: Optional[ExecutionPriority] = None,
489-
full_text: bool = False,
486+
options: WorkflowOptions,
490487
) -> WorkflowResponse:
491488
"""
492489
Sends a document to a workflow.
@@ -497,9 +494,7 @@ def _send_to_workflow(
497494
:param input_source: The document/source file to use.
498495
Has to be created beforehand.
499496
:param workflow_id: ID of the workflow.
500-
:param alias: Optional alias for the document.
501-
:param priority: Priority for the document.
502-
:param full_text: Whether to include the full OCR text response in compatible APIs.
497+
:param options: Optional options for the workflow.
503498
:return:
504499
"""
505500
if input_source is None:
@@ -509,9 +504,7 @@ def _send_to_workflow(
509504
WorkflowSettings(api_key=self.api_key, workflow_id=workflow_id)
510505
)
511506

512-
response = workflow_endpoint.workflow_execution_post(
513-
input_source, alias, priority, full_text
514-
)
507+
response = workflow_endpoint.workflow_execution_post(input_source, options)
515508

516509
dict_response = response.json()
517510

mindee/input/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
PathInput,
1010
UrlInputSource,
1111
)
12+
from mindee.input.workflow_options import WorkflowOptions

mindee/input/workflow_options.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Optional
2+
3+
from mindee.parsing.common import ExecutionPriority
4+
5+
6+
class WorkflowOptions:
7+
"""Options to pass to a workflow execution."""
8+
9+
alias: Optional[str]
10+
"""Alias for the document."""
11+
priority: Optional[ExecutionPriority]
12+
"""Priority of the document."""
13+
full_text: bool
14+
"""Whether to include the full OCR text response in compatible APIs."""
15+
public_url: Optional[str]
16+
"""A unique, encrypted URL for accessing the document validation interface without requiring authentication."""
17+
18+
def __init__(
19+
self,
20+
alias: Optional[str] = None,
21+
priority: Optional[ExecutionPriority] = None,
22+
full_text: Optional[bool] = False,
23+
public_url: Optional[str] = None,
24+
):
25+
self.alias = alias
26+
self.priority = priority
27+
self.full_text = full_text if full_text else False
28+
self.public_url = public_url

mindee/mindee_http/workflow_endpoint.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import Optional, Union
1+
from typing import Union
22

33
import requests
44

5-
from mindee.input import LocalInputSource, UrlInputSource
5+
from mindee.input import LocalInputSource, UrlInputSource, WorkflowOptions
66
from mindee.mindee_http.base_endpoint import BaseEndpoint
77
from mindee.mindee_http.workflow_settings import WorkflowSettings
8-
from mindee.parsing.common.execution_priority import ExecutionPriority
98

109

1110
class WorkflowEndpoint(BaseEndpoint):
@@ -24,29 +23,27 @@ def __init__(self, settings: WorkflowSettings) -> None:
2423
def workflow_execution_post(
2524
self,
2625
input_source: Union[LocalInputSource, UrlInputSource],
27-
alias: Optional[str] = None,
28-
priority: Optional[ExecutionPriority] = None,
29-
full_text: bool = False,
26+
options: WorkflowOptions,
3027
):
3128
"""
3229
Sends the document to the workflow.
3330
3431
:param input_source: The document/source file to use.
3532
Has to be created beforehand.
36-
:param alias: Optional alias for the document.
37-
:param priority: Priority for the document.
38-
:param full_text: Whether to include the full OCR text response in compatible APIs.
33+
:param options: Options for the workflow.
3934
:return:
4035
"""
4136
data = {}
4237

43-
if alias:
44-
data["alias"] = alias
45-
if priority:
46-
data["priority"] = priority.value
38+
if options.alias:
39+
data["alias"] = options.alias
40+
if options.priority:
41+
data["priority"] = options.priority.value
42+
if options.public_url:
43+
data["public_url"] = options.public_url
4744

4845
params = {}
49-
if full_text:
46+
if options.full_text:
5047
params["full_text_ocr"] = "true"
5148

5249
if isinstance(input_source, UrlInputSource):

tests/workflows/test_workflow_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from mindee import Client
7+
from mindee.input import WorkflowOptions
78
from mindee.parsing.common.execution_priority import ExecutionPriority
89
from tests.product import PRODUCT_DATA_DIR
910

@@ -29,10 +30,9 @@ def test_workflow(mindee_client: Client, workflow_id: str, input_path: str):
2930
current_date_time = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
3031
alias = f"python-{current_date_time}"
3132
priority = ExecutionPriority.LOW
33+
options = WorkflowOptions(alias=alias, priority=priority)
3234

33-
response = mindee_client.execute_workflow(
34-
input_source, workflow_id, alias=alias, priority=priority
35-
)
35+
response = mindee_client.execute_workflow(input_source, workflow_id, options)
3636

3737
assert response.api_request.status_code == 202
3838
assert response.execution.file.alias == f"python-{current_date_time}"

0 commit comments

Comments
 (0)