forked from phoenix/litellm-mirror
updates to exception mapping
This commit is contained in:
parent
d0b16892e0
commit
ef43141554
2 changed files with 121 additions and 13 deletions
|
@ -5,6 +5,9 @@ from openai.error import (
|
|||
RateLimitError,
|
||||
ServiceUnavailableError,
|
||||
OpenAIError,
|
||||
APIError,
|
||||
Timeout,
|
||||
APIConnectionError,
|
||||
)
|
||||
|
||||
|
||||
|
@ -29,6 +32,16 @@ class InvalidRequestError(InvalidRequestError): # type: ignore
|
|||
self.message, f"{self.model}"
|
||||
) # Call the base class constructor with the parameters it needs
|
||||
|
||||
class Timeout(Timeout): # type: ignore
|
||||
def __init__(self, message, model, llm_provider):
|
||||
self.status_code = 408
|
||||
self.message = message
|
||||
self.model = model
|
||||
self.llm_provider = llm_provider
|
||||
super().__init__(
|
||||
self.message, f"{self.model}"
|
||||
) # Call the base class constructor with the parameters it needs
|
||||
|
||||
# sub class of invalid request error - meant to give more granularity for error handling context window exceeded errors
|
||||
class ContextWindowExceededError(InvalidRequestError): # type: ignore
|
||||
def __init__(self, message, model, llm_provider):
|
||||
|
@ -63,6 +76,25 @@ class ServiceUnavailableError(ServiceUnavailableError): # type: ignore
|
|||
) # Call the base class constructor with the parameters it needs
|
||||
|
||||
|
||||
class APIError(APIError): # raise this when the API returns an invalid response object - https://github.com/openai/openai-python/blob/1be14ee34a0f8e42d3f9aa5451aa4cb161f1781f/openai/api_requestor.py#L401
|
||||
def __init__(self, status_code, message, llm_provider, model):
|
||||
self.status_code = status_code
|
||||
self.message = message
|
||||
self.llm_provider = llm_provider
|
||||
self.model = model
|
||||
super().__init__(
|
||||
self.message
|
||||
)
|
||||
|
||||
class APIConnectionError(APIConnectionError): # raised if an invalid request (not get, delete, put, post) is made
|
||||
def __init__(self, message, llm_provider, model):
|
||||
self.message = message
|
||||
self.llm_provider = llm_provider
|
||||
self.model = model
|
||||
super().__init__(
|
||||
self.message
|
||||
)
|
||||
|
||||
class OpenAIError(OpenAIError): # type: ignore
|
||||
def __init__(self, original_exception):
|
||||
self.status_code = original_exception.http_status
|
||||
|
@ -73,4 +105,4 @@ class OpenAIError(OpenAIError): # type: ignore
|
|||
headers=original_exception.headers,
|
||||
code=original_exception.code,
|
||||
)
|
||||
self.llm_provider = "openai"
|
||||
self.llm_provider = "openai"
|
Loading…
Add table
Add a link
Reference in a new issue