fix(router.py): fix should_retry logic for authentication errors

This commit is contained in:
Krrish Dholakia 2024-06-03 13:12:00 -07:00
parent 872cd2d8a0
commit a019fd05e3
2 changed files with 13 additions and 8 deletions

View file

@ -2154,7 +2154,6 @@ class Router:
- there are no fallbacks
- there are no healthy deployments in the same model group
"""
_num_healthy_deployments = 0
if healthy_deployments is not None and isinstance(healthy_deployments, list):
_num_healthy_deployments = len(healthy_deployments)
@ -2167,15 +2166,21 @@ class Router:
raise error
# Error we should only retry if there are other deployments
if isinstance(error, openai.RateLimitError) or isinstance(
error, openai.AuthenticationError
):
if isinstance(error, openai.RateLimitError):
if (
_num_healthy_deployments <= 0
and regular_fallbacks is not None
_num_healthy_deployments <= 0 # if no healthy deployments
and regular_fallbacks is not None # and fallbacks available
and len(regular_fallbacks) > 0
):
raise error
raise error # then raise the error
if isinstance(error, openai.AuthenticationError):
"""
- if other deployments available -> retry
- else -> raise error
"""
if _num_healthy_deployments <= 0: # if no healthy deployments
raise error # then raise error
return True