@@ -74,8 +74,8 @@ def output(self, is_text: bool = False) -> Any:
7474 if self ._is_stream_response (self ._original_response .headers ):
7575 raise InferenceClientError (
7676 'Response might be a stream, use the stream method instead'
77- )
78- raise InferenceClientError (f'Failed to parse response as JSON: { str (e )} ' )
77+ ) from e
78+ raise InferenceClientError (f'Failed to parse response as JSON: { str (e )} ' ) from e
7979
8080 def stream (self , chunk_size : int = 512 , as_text : bool = True ) -> Generator [Any , None , None ]:
8181 """Stream the response content.
@@ -222,10 +222,10 @@ def _make_request(self, method: str, path: str, **kwargs) -> requests.Response:
222222 )
223223 response .raise_for_status ()
224224 return response
225- except requests .exceptions .Timeout :
226- raise InferenceClientError (f'Request to { path } timed out after { timeout } seconds' )
225+ except requests .exceptions .Timeout as e :
226+ raise InferenceClientError (f'Request to { path } timed out after { timeout } seconds' ) from e
227227 except requests .exceptions .RequestException as e :
228- raise InferenceClientError (f'Request to { path } failed: { str (e )} ' )
228+ raise InferenceClientError (f'Request to { path } failed: { str (e )} ' ) from e
229229
230230 def run_sync (
231231 self ,
@@ -449,7 +449,7 @@ def health(self, healthcheck_path: str = '/health') -> requests.Response:
449449 try :
450450 return self .get (healthcheck_path )
451451 except InferenceClientError as e :
452- raise InferenceClientError (f'Health check failed: { str (e )} ' )
452+ raise InferenceClientError (f'Health check failed: { str (e )} ' ) from e
453453
454454
455455@dataclass_json (undefined = Undefined .EXCLUDE )
0 commit comments