66from mindee .error .mindee_http_error_v2 import handle_error_v2
77from mindee .input .inference_predict_options import InferencePredictOptions
88from mindee .input .local_response import LocalResponse
9- from mindee .input .page_options import PageOptions
10- from mindee .input .polling_options_v2 import PollingOptionsV2
9+ from mindee .input .polling_options import PollingOptions
1110from mindee .input .sources .local_input_source import LocalInputSource
1211from mindee .logger import logger
1312from mindee .mindee_http .mindee_api_v2 import MindeeApiV2
@@ -39,11 +38,7 @@ def __init__(self, api_key: Optional[str] = None) -> None:
3938 self .mindee_api = MindeeApiV2 (api_key )
4039
4140 def enqueue (
42- self ,
43- input_source : LocalInputSource ,
44- options : InferencePredictOptions ,
45- page_options : Optional [PageOptions ] = None ,
46- close_file : bool = True ,
41+ self , input_source : LocalInputSource , options : InferencePredictOptions
4742 ) -> PollingResponse :
4843 """
4944 Enqueues a document to a given model.
@@ -52,28 +47,19 @@ def enqueue(
5247 Has to be created beforehand.
5348
5449 :param options: Options for the prediction.
55-
56- :param close_file: Whether to ``close()`` the file after parsing it.
57- Set to ``False`` if you need to access the file after this operation.
58-
59- :param page_options: If set, remove pages from the document as specified.
60- This is done before sending the file to the server.
61- It is useful to avoid page limitations.
6250 :return: A valid inference response.
6351 """
6452 logger .debug ("Enqueuing document to '%s'" , options .model_id )
6553
66- if page_options and input_source .is_pdf ():
54+ if options . page_options and input_source .is_pdf ():
6755 input_source .process_pdf (
68- page_options .operation ,
69- page_options .on_min_pages ,
70- page_options .page_indexes ,
56+ options . page_options .operation ,
57+ options . page_options .on_min_pages ,
58+ options . page_options .page_indexes ,
7159 )
7260
7361 response = self .mindee_api .predict_async_req_post (
74- input_source = input_source ,
75- options = options ,
76- close_file = close_file ,
62+ input_source = input_source , options = options
7763 )
7864 dict_response = response .json ()
7965
@@ -103,12 +89,7 @@ def parse_queued(
10389 return InferenceResponse (dict_response )
10490
10591 def enqueue_and_parse (
106- self ,
107- input_source : LocalInputSource ,
108- options : InferencePredictOptions ,
109- polling_options : Optional [PollingOptionsV2 ] = None ,
110- page_options : Optional [PageOptions ] = None ,
111- close_file : bool = True ,
92+ self , input_source : LocalInputSource , options : InferencePredictOptions
11293 ) -> InferenceResponse :
11394 """
11495 Enqueues to an asynchronous endpoint and automatically polls for a response.
@@ -118,39 +99,25 @@ def enqueue_and_parse(
11899
119100 :param options: Options for the prediction.
120101
121- :param polling_options: Options for polling.
122-
123- :param close_file: Whether to ``close()`` the file after parsing it.
124- Set to ``False`` if you need to access the file after this operation.
125-
126- :param page_options: If set, remove pages from the document as specified.
127- This is done before sending the file to the server.
128- It is useful to avoid page limitations.
129-
130102 :return: A valid inference response.
131103 """
132- if not polling_options :
133- polling_options = PollingOptionsV2 ()
104+ if not options . polling_options :
105+ options . polling_options = PollingOptions ()
134106 self ._validate_async_params (
135- polling_options .initial_delay_sec ,
136- polling_options .delay_sec ,
137- polling_options .max_retries ,
138- )
139- queue_result = self .enqueue (
140- input_source ,
141- options ,
142- page_options ,
143- close_file ,
107+ options .polling_options .initial_delay_sec ,
108+ options .polling_options .delay_sec ,
109+ options .polling_options .max_retries ,
144110 )
111+ queue_result = self .enqueue (input_source , options )
145112 logger .debug (
146113 "Successfully enqueued document with job id: %s" , queue_result .job .id
147114 )
148- sleep (polling_options .initial_delay_sec )
115+ sleep (options . polling_options .initial_delay_sec )
149116 retry_counter = 1
150117 poll_results = self .parse_queued (
151118 queue_result .job .id ,
152119 )
153- while retry_counter < polling_options .max_retries :
120+ while retry_counter < options . polling_options .max_retries :
154121 if not isinstance (poll_results , PollingResponse ):
155122 break
156123 if poll_results .job .status == "Failed" :
@@ -160,7 +127,7 @@ def enqueue_and_parse(
160127 queue_result .job .id ,
161128 )
162129 retry_counter += 1
163- sleep (polling_options .delay_sec )
130+ sleep (options . polling_options .delay_sec )
164131 poll_results = self .parse_queued (queue_result .job .id )
165132
166133 if not isinstance (poll_results , InferenceResponse ):
0 commit comments