mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
fix(router.py): add reason for fallback failure to client-side exception string
make it easier to debug why a fallback failed to occur
This commit is contained in:
parent
1a82a6370d
commit
0de640700d
2 changed files with 23 additions and 5 deletions
|
@ -1,7 +1,14 @@
|
||||||
model_list:
|
model_list:
|
||||||
- model_name: "*"
|
- model_name: "gpt-3.5-turbo"
|
||||||
litellm_params:
|
litellm_params:
|
||||||
model: "*"
|
model: "gpt-3.5-turbo"
|
||||||
|
- model_name: "gpt-4"
|
||||||
|
litellm_params:
|
||||||
|
model: "gpt-4"
|
||||||
|
api_key: "bad_key"
|
||||||
|
- model_name: "gpt-4o"
|
||||||
|
litellm_params:
|
||||||
|
model: "gpt-4o"
|
||||||
|
|
||||||
litellm_settings:
|
litellm_settings:
|
||||||
callbacks: ["lakera_prompt_injection"]
|
fallbacks: [{"gpt-3.5-turbo": ["gpt-4", "gpt-4o"]}]
|
||||||
|
|
|
@ -2317,8 +2317,10 @@ class Router:
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if mock_testing_fallbacks is not None and mock_testing_fallbacks is True:
|
if mock_testing_fallbacks is not None and mock_testing_fallbacks is True:
|
||||||
raise Exception(
|
raise litellm.InternalServerError(
|
||||||
f"This is a mock exception for model={model_group}, to trigger a fallback. Fallbacks={fallbacks}"
|
model=model_group,
|
||||||
|
llm_provider="",
|
||||||
|
message=f"This is a mock exception for model={model_group}, to trigger a fallback. Fallbacks={fallbacks}",
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
mock_testing_context_fallbacks is not None
|
mock_testing_context_fallbacks is not None
|
||||||
|
@ -2348,6 +2350,7 @@ class Router:
|
||||||
verbose_router_logger.debug(f"Traceback{traceback.format_exc()}")
|
verbose_router_logger.debug(f"Traceback{traceback.format_exc()}")
|
||||||
original_exception = e
|
original_exception = e
|
||||||
fallback_model_group = None
|
fallback_model_group = None
|
||||||
|
fallback_failure_exception_str = ""
|
||||||
try:
|
try:
|
||||||
verbose_router_logger.debug("Trying to fallback b/w models")
|
verbose_router_logger.debug("Trying to fallback b/w models")
|
||||||
if (
|
if (
|
||||||
|
@ -2506,6 +2509,7 @@ class Router:
|
||||||
await self._async_get_cooldown_deployments_with_debug_info(),
|
await self._async_get_cooldown_deployments_with_debug_info(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
fallback_failure_exception_str = str(new_exception)
|
||||||
|
|
||||||
if hasattr(original_exception, "message"):
|
if hasattr(original_exception, "message"):
|
||||||
# add the available fallbacks to the exception
|
# add the available fallbacks to the exception
|
||||||
|
@ -2513,6 +2517,13 @@ class Router:
|
||||||
model_group,
|
model_group,
|
||||||
fallback_model_group,
|
fallback_model_group,
|
||||||
)
|
)
|
||||||
|
if len(fallback_failure_exception_str) > 0:
|
||||||
|
original_exception.message += (
|
||||||
|
"\nError doing the fallback: {}".format(
|
||||||
|
fallback_failure_exception_str
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
raise original_exception
|
raise original_exception
|
||||||
|
|
||||||
async def async_function_with_retries(self, *args, **kwargs):
|
async def async_function_with_retries(self, *args, **kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue