diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py b/.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py new file mode 100644 index 00000000..75a64707 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/litellm/proxy/common_utils/swagger_utils.py @@ -0,0 +1,48 @@ +from typing import Any, Dict + +from pydantic import BaseModel, Field + +from litellm.exceptions import LITELLM_EXCEPTION_TYPES + + +class ErrorResponse(BaseModel): + detail: Dict[str, Any] = Field( + ..., + example={ # type: ignore + "error": { + "message": "Error message", + "type": "error_type", + "param": "error_param", + "code": "error_code", + } + }, + ) + + +# Define a function to get the status code +def get_status_code(exception): + if hasattr(exception, "status_code"): + return exception.status_code + # Default status codes for exceptions without a status_code attribute + if exception.__name__ == "Timeout": + return 408 # Request Timeout + if exception.__name__ == "APIConnectionError": + return 503 # Service Unavailable + return 500 # Internal Server Error as default + + +# Create error responses +ERROR_RESPONSES = { + get_status_code(exception): { + "model": ErrorResponse, + "description": exception.__doc__ or exception.__name__, + } + for exception in LITELLM_EXCEPTION_TYPES +} + +# Ensure we have a 500 error response +if 500 not in ERROR_RESPONSES: + ERROR_RESPONSES[500] = { + "model": ErrorResponse, + "description": "Internal Server Error", + } |