mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
return ProxyException code as str
This commit is contained in:
parent
50222d808b
commit
daa0b10f51
2 changed files with 7 additions and 3 deletions
|
@ -1661,13 +1661,13 @@ class ProxyException(Exception):
|
|||
message: str,
|
||||
type: str,
|
||||
param: Optional[str],
|
||||
code: Optional[int],
|
||||
code: Optional[Union[int, str]] = None,
|
||||
headers: Optional[Dict[str, str]] = None,
|
||||
):
|
||||
self.message = message
|
||||
self.type = type
|
||||
self.param = param
|
||||
self.code = code
|
||||
self.code = str(code)
|
||||
if headers is not None:
|
||||
for k, v in headers.items():
|
||||
if not isinstance(v, str):
|
||||
|
@ -1681,7 +1681,7 @@ class ProxyException(Exception):
|
|||
"No healthy deployment available" in self.message
|
||||
or "No deployments available" in self.message
|
||||
):
|
||||
self.code = 429
|
||||
self.code = "429"
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Converts the ProxyException instance to a dictionary."""
|
||||
|
|
|
@ -79,6 +79,10 @@ def test_chat_completion_exception(client):
|
|||
in json_response["error"]["message"]
|
||||
)
|
||||
|
||||
code_in_error = json_response["error"]["code"]
|
||||
# OpenAI SDK required code to be STR, https://github.com/BerriAI/litellm/issues/4970
|
||||
assert type(code_in_error) == str
|
||||
|
||||
# make an openai client to call _make_status_error_from_response
|
||||
openai_client = openai.OpenAI(api_key="anything")
|
||||
openai_exception = openai_client._make_status_error_from_response(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue