forked from phoenix/litellm-mirror
fix(huggingface_restapi.py): return initial hf error
This commit is contained in:
parent
7cb86c4e0f
commit
194c823783
2 changed files with 17 additions and 7 deletions
|
@ -575,12 +575,20 @@ class Huggingface(BaseLLM):
|
||||||
response = await client.post(url=api_base, json=data, headers=headers)
|
response = await client.post(url=api_base, json=data, headers=headers)
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise HuggingfaceError(
|
if "error" in response_json:
|
||||||
status_code=response.status_code,
|
raise HuggingfaceError(
|
||||||
message=response.text,
|
status_code=response.status_code,
|
||||||
request=response.request,
|
message=response_json["error"],
|
||||||
response=response,
|
request=response.request,
|
||||||
)
|
response=response,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise HuggingfaceError(
|
||||||
|
status_code=response.status_code,
|
||||||
|
message=response.text,
|
||||||
|
request=response.request,
|
||||||
|
response=response,
|
||||||
|
)
|
||||||
|
|
||||||
## RESPONSE OBJECT
|
## RESPONSE OBJECT
|
||||||
return self.convert_to_model_response_object(
|
return self.convert_to_model_response_object(
|
||||||
|
@ -595,6 +603,8 @@ class Huggingface(BaseLLM):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, httpx.TimeoutException):
|
if isinstance(e, httpx.TimeoutException):
|
||||||
raise HuggingfaceError(status_code=500, message="Request Timeout Error")
|
raise HuggingfaceError(status_code=500, message="Request Timeout Error")
|
||||||
|
elif isinstance(e, HuggingfaceError):
|
||||||
|
raise e
|
||||||
elif response is not None and hasattr(response, "text"):
|
elif response is not None and hasattr(response, "text"):
|
||||||
raise HuggingfaceError(
|
raise HuggingfaceError(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
|
|
|
@ -2445,7 +2445,7 @@ async def completion(
|
||||||
)
|
)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
error_traceback = traceback.format_exc()
|
error_traceback = traceback.format_exc()
|
||||||
error_msg = f"{str(e)}\n\n{error_traceback}"
|
error_msg = f"{str(e)}"
|
||||||
raise ProxyException(
|
raise ProxyException(
|
||||||
message=getattr(e, "message", error_msg),
|
message=getattr(e, "message", error_msg),
|
||||||
type=getattr(e, "type", "None"),
|
type=getattr(e, "type", "None"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue