mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
feat - add num retries and max retries in exception
This commit is contained in:
parent
40622f5f27
commit
286d42a881
3 changed files with 24 additions and 5 deletions
|
@ -802,6 +802,7 @@ from .exceptions import (
|
||||||
APIConnectionError,
|
APIConnectionError,
|
||||||
APIResponseValidationError,
|
APIResponseValidationError,
|
||||||
UnprocessableEntityError,
|
UnprocessableEntityError,
|
||||||
|
LITELLM_EXCEPTION_TYPES,
|
||||||
)
|
)
|
||||||
from .budget_manager import BudgetManager
|
from .budget_manager import BudgetManager
|
||||||
from .proxy.proxy_cli import run_server
|
from .proxy.proxy_cli import run_server
|
||||||
|
|
|
@ -582,6 +582,25 @@ class OpenAIError(openai.OpenAIError): # type: ignore
|
||||||
self.llm_provider = "openai"
|
self.llm_provider = "openai"
|
||||||
|
|
||||||
|
|
||||||
|
LITELLM_EXCEPTION_TYPES = [
|
||||||
|
AuthenticationError,
|
||||||
|
NotFoundError,
|
||||||
|
BadRequestError,
|
||||||
|
UnprocessableEntityError,
|
||||||
|
Timeout,
|
||||||
|
PermissionDeniedError,
|
||||||
|
RateLimitError,
|
||||||
|
ContextWindowExceededError,
|
||||||
|
RejectedRequestError,
|
||||||
|
ContentPolicyViolationError,
|
||||||
|
ServiceUnavailableError,
|
||||||
|
APIError,
|
||||||
|
APIConnectionError,
|
||||||
|
APIResponseValidationError,
|
||||||
|
OpenAIError,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class BudgetExceededError(Exception):
|
class BudgetExceededError(Exception):
|
||||||
def __init__(self, current_cost, max_budget):
|
def __init__(self, current_cost, max_budget):
|
||||||
self.current_cost = current_cost
|
self.current_cost = current_cost
|
||||||
|
|
|
@ -2041,11 +2041,10 @@ class Router:
|
||||||
)
|
)
|
||||||
await asyncio.sleep(_timeout)
|
await asyncio.sleep(_timeout)
|
||||||
|
|
||||||
try:
|
if type(original_exception) in litellm.LITELLM_EXCEPTION_TYPES:
|
||||||
cooldown_deployments = await self._async_get_cooldown_deployments()
|
original_exception.max_retries = num_retries
|
||||||
original_exception.message += f"\nNumber Retries = {current_attempt + 1}, Max Retries={num_retries}\nCooldown Deployments={cooldown_deployments}"
|
original_exception.num_retries = current_attempt
|
||||||
except:
|
|
||||||
pass
|
|
||||||
raise original_exception
|
raise original_exception
|
||||||
|
|
||||||
def should_retry_this_error(
|
def should_retry_this_error(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue