mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
feat: add LiteLLM exception handling with ExInfo dataclass
This commit is contained in:
parent
dad335b8b6
commit
8bc9ebf2aa
1 changed files with 61 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
|
||||
from dataclasses import dataclass
|
||||
|
||||
def retry_exceptions():
|
||||
import httpx
|
||||
|
@ -31,4 +31,64 @@ def retry_exceptions():
|
|||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExInfo:
|
||||
name: str
|
||||
retry: bool
|
||||
description: str
|
||||
|
||||
EXCEPTIONS = [
|
||||
ExInfo("APIConnectionError", True, None),
|
||||
ExInfo("APIError", True, None),
|
||||
ExInfo("APIResponseValidationError", True, None),
|
||||
ExInfo("AuthenticationError", True, None),
|
||||
ExInfo("AzureOpenAIError", True, None),
|
||||
ExInfo("BadRequestError", True, None),
|
||||
ExInfo("BudgetExceededError", True, None),
|
||||
ExInfo("ContentPolicyViolationError", True, None),
|
||||
ExInfo("ContextWindowExceededError", True, None),
|
||||
ExInfo("InternalServerError", True, None),
|
||||
ExInfo("InvalidRequestError", True, None),
|
||||
ExInfo("JSONSchemaValidationError", True, None),
|
||||
ExInfo("NotFoundError", True, None),
|
||||
ExInfo("OpenAIError", True, None),
|
||||
ExInfo("RateLimitError", True, None),
|
||||
ExInfo("RouterRateLimitError", True, None),
|
||||
ExInfo("ServiceUnavailableError", True, None),
|
||||
ExInfo("UnprocessableEntityError", True, None),
|
||||
ExInfo("UnsupportedParamsError", True, None),
|
||||
]
|
||||
|
||||
|
||||
class LiteLLMExceptions:
|
||||
exceptions = dict()
|
||||
|
||||
def __init__(self):
|
||||
self._load()
|
||||
|
||||
def _load(self, strict=False):
|
||||
import litellm
|
||||
|
||||
for var in dir(litellm):
|
||||
if not var.endswith("Error"):
|
||||
continue
|
||||
|
||||
ex_info = None
|
||||
for exi in EXCEPTIONS:
|
||||
if var == exi.name:
|
||||
ex_info = exi
|
||||
break
|
||||
|
||||
if strict and not ex_info:
|
||||
raise ValueError(f"{var} is in litellm but not in aider's exceptions list")
|
||||
|
||||
ex = getattr(litellm, var)
|
||||
self.exceptions[ex] = ex_info
|
||||
|
||||
def exceptions_tuple(self):
|
||||
return tuple(self.exceptions)
|
||||
|
||||
|
||||
|
||||
litellm_ex = LiteLLMExceptions()
|
||||
litellm_ex._load(strict=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue