66from urllib .parse import urlparse
77from enum import Enum
88
9+
910class InferenceClientError (Exception ):
1011 """Base exception for InferenceClient errors."""
1112 pass
1213
14+
1315class AsyncStatus (int , Enum ):
1416 Initialized = 0
1517 Queue = 1
1618 Inference = 2
1719 Completed = 3
1820
21+
1922@dataclass_json (undefined = Undefined .EXCLUDE )
2023@dataclass
2124class InferenceResponse :
@@ -222,6 +225,22 @@ def _make_request(self, method: str, path: str, **kwargs) -> requests.Response:
222225 raise InferenceClientError (f"Request to { path } failed: { str (e )} " )
223226
224227 def run_sync (self , data : Dict [str , Any ], path : str = "" , timeout_seconds : int = 60 * 5 , headers : Optional [Dict [str , str ]] = None , http_method : str = "POST" , stream : bool = False ):
228+ """Make a synchronous request to the inference endpoint.
229+
230+ Args:
231+ data: The data payload to send with the request
232+ path: API endpoint path. Defaults to empty string.
233+ timeout_seconds: Request timeout in seconds. Defaults to 5 minutes.
234+ headers: Optional headers to include in the request
235+ http_method: HTTP method to use. Defaults to "POST".
236+ stream: Whether to stream the response. Defaults to False.
237+
238+ Returns:
239+ InferenceResponse: Object containing the response data.
240+
241+ Raises:
242+ InferenceClientError: If the request fails
243+ """
225244 response = self ._make_request (
226245 http_method , path , json = data , timeout_seconds = timeout_seconds , headers = headers , stream = stream )
227246
@@ -233,6 +252,23 @@ def run_sync(self, data: Dict[str, Any], path: str = "", timeout_seconds: int =
233252 )
234253
235254 def run (self , data : Dict [str , Any ], path : str = "" , timeout_seconds : int = 60 * 5 , headers : Optional [Dict [str , str ]] = None , http_method : str = "POST" , no_response : bool = False ):
255+ """Make an asynchronous request to the inference endpoint.
256+
257+ Args:
258+ data: The data payload to send with the request
259+ path: API endpoint path. Defaults to empty string.
260+ timeout_seconds: Request timeout in seconds. Defaults to 5 minutes.
261+ headers: Optional headers to include in the request
262+ http_method: HTTP method to use. Defaults to "POST".
263+ no_response: If True, don't wait for response. Defaults to False.
264+
265+ Returns:
266+ AsyncInferenceExecution: Object to track the async execution status.
267+ If no_response is True, returns None.
268+
269+ Raises:
270+ InferenceClientError: If the request fails
271+ """
236272 # Add relevant headers to the request, to indicate that the request is async
237273 headers = headers or {}
238274 if no_response :
0 commit comments