2020from mindee .parsing .v2 .inference_response import InferenceResponse
2121from mindee .parsing .v2 .job_response import JobResponse
2222
23- TypeBaseInferenceResponse = TypeVar ("TypeBaseInferenceResponse " , bound = BaseResponse )
23+ TypeBaseResponse = TypeVar ("TypeBaseResponse " , bound = BaseResponse )
2424
2525
2626class ClientV2 (ClientMixin ):
@@ -100,44 +100,15 @@ def get_job(self, job_id: str) -> JobResponse:
100100 def get_inference (
101101 self ,
102102 inference_id : str ,
103- response_type : Type [BaseResponse ] = InferenceResponse ,
104- disable_redundant_warnings : bool = False ,
105103 ) -> BaseResponse :
106104 """[Deprecated] Use `get_result` instead."""
107- if not disable_redundant_warnings :
108- warnings .warn (
109- "get_inference is deprecated; use get_result instead" ,
110- DeprecationWarning ,
111- stacklevel = 2 ,
112- )
113- return self .get_result (inference_id , response_type )
105+ return self .get_result (InferenceResponse , inference_id )
114106
115107 def get_result (
116108 self ,
109+ response_type : Type [TypeBaseResponse ],
117110 inference_id : str ,
118- response_type : Optional [Type [BaseResponse ]] = InferenceResponse ,
119- ) -> BaseResponse :
120- """
121- Get the result of an inference that was previously enqueued.
122-
123- The inference will only be available after it has finished processing.
124-
125- :param inference_id: UUID of the inference to retrieve.
126- :param response_type: Class of the product to instantiate.
127- :return: An inference response.
128- """
129- response_type = response_type or InferenceResponse
130- response = self ._get_result (inference_id , response_type )
131- assert isinstance (response , response_type ), (
132- f'Invalid response type "{ type (response )} "'
133- )
134- return response
135-
136- def _get_result (
137- self ,
138- inference_id : str ,
139- response_type : Type [BaseResponse ] = InferenceResponse ,
140- ) -> BaseResponse :
111+ ) -> TypeBaseResponse :
141112 """
142113 Get the result of an inference that was previously enqueued.
143114
@@ -157,12 +128,12 @@ def _get_result(
157128 dict_response = response .json ()
158129 return response_type (dict_response )
159130
160- def _enqueue_and_get (
131+ def enqueue_and_get_result (
161132 self ,
133+ response_type : Type [TypeBaseResponse ],
162134 input_source : Union [LocalInputSource , UrlInputSource ],
163135 params : BaseParameters ,
164- response_type : Optional [Type [BaseResponse ]] = InferenceResponse ,
165- ) -> BaseResponse :
136+ ) -> TypeBaseResponse :
166137 """
167138 Enqueues to an asynchronous endpoint and automatically polls for a response.
168139
@@ -187,6 +158,7 @@ def _enqueue_and_get(
187158 try_counter = 0
188159 while try_counter < params .polling_options .max_retries :
189160 job_response = self .get_job (enqueue_response .job .id )
161+ assert isinstance (job_response , JobResponse )
190162 if job_response .job .status == CommonStatus .FAILED .value :
191163 if job_response .job .error :
192164 detail = job_response .job .error .detail
@@ -196,8 +168,11 @@ def _enqueue_and_get(
196168 f"Parsing failed for job { job_response .job .id } : { detail } "
197169 )
198170 if job_response .job .status == CommonStatus .PROCESSED .value :
199- result = self .get_inference (
200- job_response .job .id , response_type or InferenceResponse , True
171+ result = self .get_result (
172+ response_type or InferenceResponse , job_response .job .id
173+ )
174+ assert isinstance (result , response_type ), (
175+ f'Invalid response type "{ type (result )} "'
201176 )
202177 return result
203178 try_counter += 1
@@ -212,35 +187,12 @@ def enqueue_and_get_inference(
212187 ) -> InferenceResponse :
213188 """[Deprecated] Use `enqueue_and_get_result` instead."""
214189 warnings .warn (
215- "enqueue_and_get_inference is deprecated; use enqueue_and_get_result" ,
190+ "enqueue_and_get_inference is deprecated; use enqueue_and_get_result instead " ,
216191 DeprecationWarning ,
217192 stacklevel = 2 ,
218193 )
219- response = self ._enqueue_and_get ( input_source , params )
194+ response = self .enqueue_and_get_result ( InferenceResponse , input_source , params )
220195 assert isinstance (response , InferenceResponse ), (
221196 f'Invalid response type "{ type (response )} "'
222197 )
223198 return response
224-
225- def enqueue_and_get_result (
226- self ,
227- response_type : Type [TypeBaseInferenceResponse ],
228- input_source : Union [LocalInputSource , UrlInputSource ],
229- params : BaseParameters ,
230- ) -> TypeBaseInferenceResponse :
231- """
232- Enqueues to an asynchronous endpoint and automatically polls for a response.
233-
234- :param input_source: The document/source file to use. Can be local or remote.
235-
236- :param params: Parameters to set when sending a file.
237-
238- :param response_type: The product class to use for the response object.
239-
240- :return: A valid inference response.
241- """
242- response = self ._enqueue_and_get (input_source , params , response_type )
243- assert isinstance (response , response_type ), (
244- f'Invalid response type "{ type (response )} "'
245- )
246- return response
0 commit comments