@@ -13,16 +13,23 @@ class Endpoint(BaseEndpoint):
1313 settings : MindeeAPI
1414
1515 def __init__ (
16- self , url_name : str , owner : str , version : str , settings : MindeeAPI
16+ self ,
17+ url_name : str ,
18+ owner : str ,
19+ version : str ,
20+ settings : MindeeAPI ,
21+ http_client : httpx .Client | None = None ,
1722 ) -> None :
1823 """
1924 Generic API endpoint for a product.
2025
2126 :param owner: owner of the product
2227 :param url_name: name of the product as it appears in the URL
2328 :param version: interface version
29+ :param settings: settings for the API
30+ :param http_client: HTTP client for making requests.
2431 """
25- super ().__init__ (settings )
32+ super ().__init__ (settings , http_client )
2633 self .owner = owner
2734 self .url_name = url_name
2835 self .version = version
@@ -42,7 +49,8 @@ def predict_req_post(
4249 :param include_words: Include raw OCR words in the response
4350 :param close_file: Whether to `close()` the file after parsing it.
4451 :param cropper: Including Mindee cropping results.
45- :param full_text: Whether to include the full OCR text response in compatible APIs.
52+ :param full_text: Whether to include the full OCR text response in compatible
53+ APIs.
4654 :return: httpx response
4755 """
4856 return self ._custom_request (
@@ -66,7 +74,8 @@ def predict_async_req_post(
6674 :param include_words: Include raw OCR words in the response
6775 :param close_file: Whether to `close()` the file after parsing it.
6876 :param cropper: Including Mindee cropping results.
69- :param full_text: Whether to include the full OCR text response in compatible APIs.
77+ :param full_text: Whether to include the full OCR text response in compatible
78+ APIs.
7079 :param workflow_id: Workflow ID.
7180 :param rag: If set, will enable Retrieval-Augmented Generation.
7281 :return: httpx response
@@ -112,7 +121,7 @@ def _custom_request(
112121
113122 if isinstance (input_source , URLInputSource ):
114123 data ["document" ] = input_source .url
115- response = httpx .post (
124+ response = self . http_client .post (
116125 url = url ,
117126 headers = self .settings .base_headers ,
118127 data = data ,
@@ -121,7 +130,7 @@ def _custom_request(
121130 )
122131 else :
123132 files = {"document" : input_source .read_contents (close_file )}
124- response = httpx .post (
133+ response = self . http_client .post (
125134 url = url ,
126135 files = files ,
127136 headers = self .settings .base_headers ,
@@ -138,7 +147,7 @@ def document_queue_req_get(self, queue_id: str) -> httpx.Response:
138147
139148 :param queue_id: queue_id received from the API
140149 """
141- return httpx .get (
150+ return self . http_client .get (
142151 f"{ self .settings .url_root } /documents/queue/{ queue_id } " ,
143152 headers = self .settings .base_headers ,
144153 timeout = self .settings .request_timeout ,
@@ -147,7 +156,7 @@ def document_queue_req_get(self, queue_id: str) -> httpx.Response:
147156
148157 def openapi_get_req (self ) -> httpx .Response :
149158 """Get the OpenAPI specification of the product."""
150- return httpx .get (
159+ return self . http_client .get (
151160 f"{ self .settings .url_root } /openapi.json" ,
152161 headers = self .settings .base_headers ,
153162 timeout = self .settings .request_timeout ,
@@ -163,7 +172,7 @@ def document_feedback_req_put(
163172 :param document_id: ID of the document to send feedback to.
164173 :param feedback: Feedback object to send.
165174 """
166- return httpx .put (
175+ return self . http_client .put (
167176 f"{ self .settings .base_url } /v1/documents/{ document_id } /feedback" ,
168177 headers = self .settings .base_headers ,
169178 data = feedback ,
@@ -187,7 +196,7 @@ def training_req_post(
187196 files = {"document" : input_source .read_contents (close_file )}
188197 params = {"training" : True , "with_candidates" : True }
189198
190- response = httpx .post (
199+ response = self . http_client .post (
191200 f"{ self .settings .url_root } /predict" ,
192201 files = files ,
193202 headers = self .settings .base_headers ,
@@ -209,7 +218,7 @@ def training_async_req_post(
209218 files = {"document" : input_source .read_contents (close_file )}
210219 params = {"training" : True , "async" : True }
211220
212- response = httpx .post (
221+ response = self . http_client .post (
213222 f"{ self .settings .url_root } /predict" ,
214223 files = files ,
215224 headers = self .settings .base_headers ,
@@ -240,7 +249,7 @@ def documents_req_get(self, page_id: int = 1) -> httpx.Response:
240249 params = {
241250 "page" : page_id ,
242251 }
243- response = httpx .get (
252+ response = self . http_client .get (
244253 f"{ self .settings .url_root } /documents" ,
245254 headers = self .settings .base_headers ,
246255 params = params ,
@@ -260,7 +269,7 @@ def document_req_get(self, document_id: str) -> httpx.Response:
260269 "include_candidates" : True ,
261270 "global_orientation" : True ,
262271 }
263- response = httpx .get (
272+ response = self . http_client .get (
264273 f"{ self .settings .url_root } /documents/{ document_id } " ,
265274 headers = self .settings .base_headers ,
266275 params = params ,
@@ -279,7 +288,7 @@ def annotations_req_post(
279288 :param annotations: Annotations object
280289 :return: httpx response
281290 """
282- response = httpx .post (
291+ response = self . http_client .post (
283292 f"{ self .settings .url_root } /documents/{ document_id } /annotations" ,
284293 headers = self .settings .base_headers ,
285294 json = annotations ,
@@ -297,7 +306,7 @@ def annotations_req_put(
297306 :param annotations: Annotations object
298307 :return: httpx response
299308 """
300- response = httpx .put (
309+ response = self . http_client .put (
301310 f"{ self .settings .url_root } /documents/{ document_id } /annotations" ,
302311 headers = self .settings .base_headers ,
303312 json = annotations ,
@@ -312,7 +321,7 @@ def annotations_req_del(self, document_id: str) -> httpx.Response:
312321 :param document_id: ID of the document to annotate
313322 :return: httpx response
314323 """
315- response = httpx .delete (
324+ response = self . http_client .delete (
316325 f"{ self .settings .url_root } /documents/{ document_id } /annotations" ,
317326 headers = self .settings .base_headers ,
318327 timeout = self .settings .request_timeout ,
0 commit comments