@@ -32,9 +32,8 @@ def get_bound_classname(type_var) -> str:
32
32
33
33
def _clean_account_name (account_name : str ) -> str :
34
34
"""
35
- Checks that an account name is provided for custom builds , and sets the default one otherwise.
35
+ Checks that an account name is provided for custom products , and sets the default one otherwise.
36
36
37
- :param product_class: product class to use for API calls.
38
37
:param account_name: name of the account's holder. Only needed for custom products.
39
38
"""
40
39
if not account_name or len (account_name ) < 1 :
@@ -80,7 +79,7 @@ def parse(
80
79
The response object will be instantiated based on this parameter.
81
80
82
81
:param input_source: The document/source file to use.
83
- Has to be be created beforehand.
82
+ Has to be created beforehand.
84
83
85
84
:param include_words: Whether to include the full text for each page.
86
85
This performs a full OCR operation on the server and will increase response time.
@@ -133,7 +132,7 @@ def enqueue(
133
132
The response object will be instantiated based on this parameter.
134
133
135
134
:param input_source: The document/source file to use.
136
- Has to be be created beforehand.
135
+ Has to be created beforehand.
137
136
138
137
:param include_words: Whether to include the full text for each page.
139
138
This performs a full OCR operation on the server and will increase response time.
@@ -166,7 +165,12 @@ def enqueue(
166
165
page_options .page_indexes ,
167
166
)
168
167
return self ._predict_async (
169
- product_class , input_source , include_words , close_file , cropper , endpoint
168
+ product_class ,
169
+ input_source ,
170
+ endpoint ,
171
+ include_words ,
172
+ close_file ,
173
+ cropper ,
170
174
)
171
175
172
176
def parse_queued (
@@ -191,16 +195,21 @@ def parse_queued(
191
195
return self ._get_queued_document (product_class , endpoint , queue_id )
192
196
193
197
def _validate_async_params (
194
- self , initial_delay_sec : float , delay_sec : float
198
+ self , initial_delay_sec : float , delay_sec : float , max_retries : int
195
199
) -> None :
196
- if delay_sec < 2 :
200
+ min_delay = 1
201
+ min_initial_delay = 2
202
+ min_retries = 2
203
+ if delay_sec < min_delay :
197
204
raise MindeeClientError (
198
- "Cannot set auto-parsing delay to less than 2 seconds."
205
+ f "Cannot set auto-parsing delay to less than { min_delay } seconds."
199
206
)
200
- if initial_delay_sec < 4 :
207
+ if initial_delay_sec < min_initial_delay :
201
208
raise MindeeClientError (
202
- "Cannot set initial parsing delay to less than 4 seconds."
209
+ f "Cannot set initial parsing delay to less than { min_initial_delay } seconds."
203
210
)
211
+ if max_retries < min_retries :
212
+ raise MindeeClientError (f"Cannot set retries to less than { min_retries } ." )
204
213
205
214
def enqueue_and_parse (
206
215
self ,
@@ -222,7 +231,7 @@ def enqueue_and_parse(
222
231
The response object will be instantiated based on this parameter.
223
232
224
233
:param input_source: The document/source file to use.
225
- Has to be be created beforehand.
234
+ Has to be created beforehand.
226
235
227
236
:param include_words: Whether to include the full text for each page.
228
237
This performs a full OCR operation on the server and will increase response time.
@@ -246,9 +255,8 @@ def enqueue_and_parse(
246
255
This should not be shorter than 2 seconds.
247
256
248
257
:param max_retries: Total amount of polling attempts.
249
-
250
258
"""
251
- self ._validate_async_params (initial_delay_sec , delay_sec )
259
+ self ._validate_async_params (initial_delay_sec , delay_sec , max_retries )
252
260
if not endpoint :
253
261
endpoint = self ._initialize_ots_endpoint (product_class )
254
262
queue_result = self .enqueue (
@@ -345,16 +353,12 @@ def _predict_async(
345
353
self ,
346
354
product_class : Type [Inference ],
347
355
input_source : Union [LocalInputSource , UrlInputSource ],
356
+ endpoint : Optional [Endpoint ] = None ,
348
357
include_words : bool = False ,
349
358
close_file : bool = True ,
350
359
cropper : bool = False ,
351
- endpoint : Optional [Endpoint ] = None ,
352
360
) -> AsyncPredictResponse :
353
- """
354
- Sends a document to the queue, and sends back an asynchronous predict response.
355
-
356
- :param doc_config: Configuration of the document.
357
- """
361
+ """Sends a document to the queue, and sends back an asynchronous predict response."""
358
362
if input_source is None :
359
363
raise MindeeClientError ("No input document provided" )
360
364
if not endpoint :
@@ -384,7 +388,6 @@ def _get_queued_document(
384
388
Fetches a document or a Job from a given queue.
385
389
386
390
:param queue_id: Queue_id received from the API
387
- :param doc_config: Pre-checked document configuration.
388
391
"""
389
392
queue_response = endpoint .document_queue_req_get (queue_id = queue_id )
390
393
@@ -436,8 +439,6 @@ def create_endpoint(
436
439
:param account_name: Your organization's username on the API Builder
437
440
:param version: If set, locks the version of the model to use.
438
441
If not set, use the latest version of the model.
439
- :param product_class: A document class in which the response will be extracted.
440
- Must inherit from ``mindee.product.base.Document``.
441
442
"""
442
443
if len (endpoint_name ) == 0 :
443
444
raise MindeeClientError ("Custom endpoint require a valid 'endpoint_name'." )
@@ -456,6 +457,8 @@ def source_from_path(
456
457
Load a document from an absolute path, as a string.
457
458
458
459
:param input_path: Path of file to open
460
+ :param fix_pdf: Whether to attempt fixing PDF files before sending.
461
+ Setting this to `True` can modify the data sent to Mindee.
459
462
"""
460
463
input_doc = PathInput (input_path )
461
464
if fix_pdf :
@@ -469,6 +472,8 @@ def source_from_file(
469
472
Load a document from a normal Python file object/handle.
470
473
471
474
:param input_file: Input file handle
475
+ :param fix_pdf: Whether to attempt fixing PDF files before sending.
476
+ Setting this to `True` can modify the data sent to Mindee.
472
477
"""
473
478
input_doc = FileInput (input_file )
474
479
if fix_pdf :
@@ -483,6 +488,8 @@ def source_from_b64string(
483
488
484
489
:param input_string: Input to parse as base64 string
485
490
:param filename: The name of the file (without the path)
491
+ :param fix_pdf: Whether to attempt fixing PDF files before sending.
492
+ Setting this to `True` can modify the data sent to Mindee.
486
493
"""
487
494
input_doc = Base64Input (input_string , filename )
488
495
if fix_pdf :
@@ -497,6 +504,8 @@ def source_from_bytes(
497
504
498
505
:param input_bytes: Raw byte input
499
506
:param filename: The name of the file (without the path)
507
+ :param fix_pdf: Whether to attempt fixing PDF files before sending.
508
+ Setting this to `True` can modify the data sent to Mindee.
500
509
"""
501
510
input_doc = BytesInput (input_bytes , filename )
502
511
if fix_pdf :
@@ -508,7 +517,7 @@ def source_from_url(
508
517
url : str ,
509
518
) -> UrlInputSource :
510
519
"""
511
- Load a document from an URL.
520
+ Load a document from a URL.
512
521
513
522
:param url: Raw byte input
514
523
"""
0 commit comments