fix(router.py): raise better exception when no deployments are available

Fixes https://github.com/BerriAI/litellm/issues/3355
This commit is contained in:
Krrish Dholakia 2024-04-29 18:48:04 -07:00
parent 1e53c06064
commit f0e48cdd53

View file

@ -1450,7 +1450,9 @@ class Router:
raise original_exception raise original_exception
### RETRY ### RETRY
#### check if it should retry + back-off if required #### check if it should retry + back-off if required
if "No models available" in str(e): if "No models available" in str(
e
) or RouterErrors.no_deployments_available.value in str(e):
timeout = litellm._calculate_retry_after( timeout = litellm._calculate_retry_after(
remaining_retries=num_retries, remaining_retries=num_retries,
max_retries=num_retries, max_retries=num_retries,
@ -2948,6 +2950,11 @@ class Router:
model=model, healthy_deployments=healthy_deployments, messages=messages model=model, healthy_deployments=healthy_deployments, messages=messages
) )
if len(healthy_deployments) == 0:
raise ValueError(
f"{RouterErrors.no_deployments_available.value}, passed model={model}"
)
if ( if (
self.routing_strategy == "usage-based-routing-v2" self.routing_strategy == "usage-based-routing-v2"
and self.lowesttpm_logger_v2 is not None and self.lowesttpm_logger_v2 is not None