refactor: Simplify error handling and remove unused retry exceptions code

This commit is contained in:
Paul Gauthier 2024-11-07 13:02:04 -08:00 committed by Paul Gauthier (aider)
parent 8d4175536f
commit 816fd5e65c
3 changed files with 54 additions and 138 deletions

View file

@ -1,37 +1,6 @@
from dataclasses import dataclass
def retry_exceptions():
import httpx
import openai
return (
# httpx
httpx.ConnectError,
httpx.RemoteProtocolError,
httpx.ReadTimeout,
#
# litellm exceptions inherit from openai exceptions
# https://docs.litellm.ai/docs/exception_mapping
#
# openai.BadRequestError,
# litellm.ContextWindowExceededError,
# litellm.ContentPolicyViolationError,
#
# openai.AuthenticationError,
# openai.PermissionDeniedError,
# openai.NotFoundError,
#
openai.APITimeoutError,
openai.UnprocessableEntityError,
openai.RateLimitError,
openai.APIConnectionError,
# openai.APIError,
# openai.APIStatusError,
openai.InternalServerError,
)
@dataclass
class ExInfo:
name: str
@ -43,20 +12,20 @@ EXCEPTIONS = [
ExInfo("APIConnectionError", True, None),
ExInfo("APIError", True, None),
ExInfo("APIResponseValidationError", True, None),
ExInfo("AuthenticationError", True, None),
ExInfo("AuthenticationError", False, "The API provider is not able to authenticate you. Check your API key."),
ExInfo("AzureOpenAIError", True, None),
ExInfo("BadRequestError", True, None),
ExInfo("BadRequestError", False, None),
ExInfo("BudgetExceededError", True, None),
ExInfo("ContentPolicyViolationError", True, None),
ExInfo("ContextWindowExceededError", True, None),
ExInfo("InternalServerError", True, None),
ExInfo("ContentPolicyViolationError", True, "The API provider has refused the request due to a safety policy about the content."),
ExInfo("ContextWindowExceededError", False, None), # special case handled in base_coder
ExInfo("InternalServerError", True, "The API provider's servers are down or overloaded."),
ExInfo("InvalidRequestError", True, None),
ExInfo("JSONSchemaValidationError", True, None),
ExInfo("NotFoundError", True, None),
ExInfo("NotFoundError", False, None),
ExInfo("OpenAIError", True, None),
ExInfo("RateLimitError", True, None),
ExInfo("RateLimitError", True, "The API provider has rate limited you. Try again later or check your quotas."),
ExInfo("RouterRateLimitError", True, None),
ExInfo("ServiceUnavailableError", True, None),
ExInfo("ServiceUnavailableError", True, "The API provider's servers are down or overloaded."),
ExInfo("UnprocessableEntityError", True, None),
ExInfo("UnsupportedParamsError", True, None),
]
@ -92,7 +61,7 @@ class LiteLLMExceptions:
def get_ex_info(self, ex):
"""Return the ExInfo for a given exception instance"""
return self.exceptions.get(ex.__class__)
return self.exceptions.get(ex.__class__, ExInfo(None, None, None))
litellm_ex = LiteLLMExceptions()