forked from phoenix/litellm-mirror
fix(utils.py): fix status code in exception mapping
This commit is contained in:
parent
e3ca2789df
commit
b23a633cf1
2 changed files with 11 additions and 16 deletions
|
@ -2337,7 +2337,7 @@ class Router:
|
||||||
original_exception = e
|
original_exception = e
|
||||||
fallback_model_group = None
|
fallback_model_group = None
|
||||||
try:
|
try:
|
||||||
verbose_router_logger.debug(f"Trying to fallback b/w models")
|
verbose_router_logger.debug("Trying to fallback b/w models")
|
||||||
if (
|
if (
|
||||||
hasattr(e, "status_code")
|
hasattr(e, "status_code")
|
||||||
and e.status_code == 400 # type: ignore
|
and e.status_code == 400 # type: ignore
|
||||||
|
@ -2346,6 +2346,9 @@ class Router:
|
||||||
or isinstance(e, litellm.ContentPolicyViolationError)
|
or isinstance(e, litellm.ContentPolicyViolationError)
|
||||||
)
|
)
|
||||||
): # don't retry a malformed request
|
): # don't retry a malformed request
|
||||||
|
verbose_router_logger.debug(
|
||||||
|
"Not retrying request as it's malformed. Status code=400."
|
||||||
|
)
|
||||||
raise e
|
raise e
|
||||||
if isinstance(e, litellm.ContextWindowExceededError):
|
if isinstance(e, litellm.ContextWindowExceededError):
|
||||||
if context_window_fallbacks is not None:
|
if context_window_fallbacks is not None:
|
||||||
|
@ -2484,6 +2487,12 @@ class Router:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose_router_logger.error(f"An exception occurred - {str(e)}")
|
verbose_router_logger.error(f"An exception occurred - {str(e)}")
|
||||||
verbose_router_logger.debug(traceback.format_exc())
|
verbose_router_logger.debug(traceback.format_exc())
|
||||||
|
|
||||||
|
if hasattr(original_exception, "message"):
|
||||||
|
# add the available fallbacks to the exception
|
||||||
|
original_exception.message += "\nReceived Model Group={}\nAvailable Model Group Fallbacks={}".format(
|
||||||
|
model_group, fallback_model_group
|
||||||
|
)
|
||||||
raise original_exception
|
raise original_exception
|
||||||
|
|
||||||
async def async_function_with_retries(self, *args, **kwargs):
|
async def async_function_with_retries(self, *args, **kwargs):
|
||||||
|
|
|
@ -4319,6 +4319,7 @@ def get_formatted_prompt(
|
||||||
prompt = data["prompt"]
|
prompt = data["prompt"]
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
|
||||||
def get_response_string(response_obj: ModelResponse) -> str:
|
def get_response_string(response_obj: ModelResponse) -> str:
|
||||||
_choices: List[Union[Choices, StreamingChoices]] = response_obj.choices
|
_choices: List[Union[Choices, StreamingChoices]] = response_obj.choices
|
||||||
|
|
||||||
|
@ -7720,11 +7721,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=httpx.Response(
|
|
||||||
status_code=400,
|
|
||||||
content=str(original_exception),
|
|
||||||
request=httpx.Request(method="completion", url="https://github.com/BerriAI/litellm"), # type: ignore
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
elif "This model's maximum context length is" in error_str:
|
elif "This model's maximum context length is" in error_str:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7733,7 +7729,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif "DeploymentNotFound" in error_str:
|
elif "DeploymentNotFound" in error_str:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7742,7 +7737,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
(
|
(
|
||||||
|
@ -7762,7 +7756,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=getattr(original_exception, "response", None),
|
|
||||||
)
|
)
|
||||||
elif "invalid_request_error" in error_str:
|
elif "invalid_request_error" in error_str:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7771,7 +7764,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=getattr(original_exception, "response", None),
|
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
"The api_key client option must be set either by passing api_key to the client or by setting"
|
"The api_key client option must be set either by passing api_key to the client or by setting"
|
||||||
|
@ -7783,7 +7775,6 @@ def exception_type(
|
||||||
llm_provider=custom_llm_provider,
|
llm_provider=custom_llm_provider,
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif hasattr(original_exception, "status_code"):
|
elif hasattr(original_exception, "status_code"):
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7794,7 +7785,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 401:
|
elif original_exception.status_code == 401:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7803,7 +7793,6 @@ def exception_type(
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
model=model,
|
model=model,
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 408:
|
elif original_exception.status_code == 408:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7820,7 +7809,6 @@ def exception_type(
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 429:
|
elif original_exception.status_code == 429:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7829,7 +7817,6 @@ def exception_type(
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 503:
|
elif original_exception.status_code == 503:
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
@ -7838,7 +7825,6 @@ def exception_type(
|
||||||
model=model,
|
model=model,
|
||||||
llm_provider="azure",
|
llm_provider="azure",
|
||||||
litellm_debug_info=extra_information,
|
litellm_debug_info=extra_information,
|
||||||
response=original_exception.response,
|
|
||||||
)
|
)
|
||||||
elif original_exception.status_code == 504: # gateway timeout error
|
elif original_exception.status_code == 504: # gateway timeout error
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue