Commit 71e521ff authored by Your Name's avatar Your Name

Fix: Move ERROR_CODE_MAP inside try block to handle litellm import error gracefully

parent ae1820e5
...@@ -21,21 +21,21 @@ try: ...@@ -21,21 +21,21 @@ try:
ContextWindowExceededError, ContextWindowExceededError,
) )
LITELLM_AVAILABLE = True LITELLM_AVAILABLE = True
# Map litellm exceptions to OpenAI error codes
ERROR_CODE_MAP = {
AuthenticationError: {"code": 401, "type": "invalid_api_key"},
BadRequestError: {"code": 400, "type": "invalid_request_error"},
RateLimitError: {"code": 429, "type": "rate_limit_error"},
ServiceUnavailableError: {"code": 503, "type": "service_unavailable"},
ContextWindowExceededError: {"code": 400, "type": "context_window_exceeded"},
}
except ImportError: except ImportError:
LITELLM_AVAILABLE = False LITELLM_AVAILABLE = False
litellm = None litellm = None
completion = None completion = None
acompletion = None acompletion = None
ERROR_CODE_MAP = {}
# Map litellm exceptions to OpenAI error codes
ERROR_CODE_MAP = {
AuthenticationError: {"code": 401, "type": "invalid_api_key"},
BadRequestError: {"code": 400, "type": "invalid_request_error"},
RateLimitError: {"code": 429, "type": "rate_limit_error"},
ServiceUnavailableError: {"code": 503, "type": "service_unavailable"},
ContextWindowExceededError: {"code": 400, "type": "context_window_exceeded"},
}
def get_error_response(status_code: int, message: str, error_type: str = "internal_error") -> Dict: def get_error_response(status_code: int, message: str, error_type: str = "internal_error") -> Dict:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment