(Proxy) add support for DOCS_URL and REDOC_URL (#6806)

* add support for DOCS_URL and REDOC_URL

* document env vars

* add unit tests for docs url and redocs url
This commit is contained in:
Ishaan Jaff 2024-11-19 07:02:12 -08:00 committed by GitHub
parent 7550aba474
commit 1890fde3f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 79 additions and 3 deletions

View file

@ -3099,6 +3099,34 @@ def get_error_message_str(e: Exception) -> str:
return error_message
def _get_redoc_url() -> str:
"""
Get the redoc URL from the environment variables.
- If REDOC_URL is set, return it.
- Otherwise, default to "/redoc".
"""
return os.getenv("REDOC_URL", "/redoc")
def _get_docs_url() -> Optional[str]:
"""
Get the docs URL from the environment variables.
- If DOCS_URL is set, return it.
- If NO_DOCS is True, return None.
- Otherwise, default to "/".
"""
docs_url = os.getenv("DOCS_URL", None)
if docs_url:
return docs_url
if os.getenv("NO_DOCS", "False") == "True":
return None
# default to "/"
return "/"
def handle_exception_on_proxy(e: Exception) -> ProxyException:
"""
Returns an Exception as ProxyException, this ensures all exceptions are OpenAI API compatible
@ -3120,3 +3148,4 @@ def handle_exception_on_proxy(e: Exception) -> ProxyException:
param=getattr(e, "param", "None"),
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)