mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
Swagger - bump DOMPurify version + add back Support local swagger bundle (good for airgapped environments) + support local swagger on custom root paths (#12911)
* fix(proxy_server.py): update swagger-ui-bundle.js + bring back swagger in airgapped environments * fix(proxy_server.py): support local swagger on custom root path enables on prem usage of litellm
This commit is contained in:
parent
0d2e280e78
commit
c5c2a68510
2 changed files with 34 additions and 24 deletions
|
|
@ -877,21 +877,29 @@ app.add_middleware(
|
|||
|
||||
app.add_middleware(PrometheusAuthMiddleware)
|
||||
|
||||
swagger_path = os.path.join(current_dir, "swagger")
|
||||
router.mount("/swagger", StaticFiles(directory=swagger_path), name="swagger")
|
||||
|
||||
def mount_swagger_ui():
|
||||
swagger_directory = os.path.join(current_dir, "swagger")
|
||||
swagger_path = "/" if server_root_path is None else server_root_path
|
||||
if not swagger_path.endswith("/"):
|
||||
swagger_path = swagger_path + "/"
|
||||
custom_root_path_swagger_path = swagger_path + "swagger"
|
||||
|
||||
app.mount("/swagger", StaticFiles(directory=swagger_directory), name="swagger")
|
||||
|
||||
def swagger_monkey_patch(*args, **kwargs):
|
||||
return get_swagger_ui_html(
|
||||
*args,
|
||||
**kwargs,
|
||||
swagger_js_url=f"{custom_root_path_swagger_path}/swagger-ui-bundle.js",
|
||||
swagger_css_url=f"{custom_root_path_swagger_path}/swagger-ui.css",
|
||||
swagger_favicon_url=f"{custom_root_path_swagger_path}/favicon.png",
|
||||
)
|
||||
|
||||
applications.get_swagger_ui_html = swagger_monkey_patch
|
||||
|
||||
|
||||
# def swagger_monkey_patch(*args, **kwargs):
|
||||
# return get_swagger_ui_html(
|
||||
# *args,
|
||||
# **kwargs,
|
||||
# swagger_js_url="/swagger/swagger-ui-bundle.js",
|
||||
# swagger_css_url="/swagger/swagger-ui.css",
|
||||
# swagger_favicon_url="/swagger/favicon.png",
|
||||
# )
|
||||
|
||||
|
||||
# applications.get_swagger_ui_html = swagger_monkey_patch
|
||||
mount_swagger_ui()
|
||||
|
||||
from typing import Dict
|
||||
|
||||
|
|
@ -3671,7 +3679,7 @@ async def model_list(
|
|||
Use `/model/info` - to get detailed model information, example - pricing, mode, etc.
|
||||
|
||||
This is just for compatibility with openai projects like aider.
|
||||
|
||||
|
||||
Query Parameters:
|
||||
- include_metadata: Include additional metadata in the response with fallback information
|
||||
- fallback_type: Type of fallbacks to include ("general", "context_window", "content_policy")
|
||||
|
|
@ -3745,31 +3753,33 @@ async def model_list(
|
|||
"created": DEFAULT_MODEL_CREATED_AT_TIME,
|
||||
"owned_by": "openai",
|
||||
}
|
||||
|
||||
|
||||
# Add metadata if requested
|
||||
if include_metadata:
|
||||
metadata = {}
|
||||
|
||||
|
||||
# Default fallback_type to "general" if include_metadata is true
|
||||
effective_fallback_type = fallback_type if fallback_type is not None else "general"
|
||||
|
||||
effective_fallback_type = (
|
||||
fallback_type if fallback_type is not None else "general"
|
||||
)
|
||||
|
||||
# Validate fallback_type
|
||||
valid_fallback_types = ["general", "context_window", "content_policy"]
|
||||
if effective_fallback_type not in valid_fallback_types:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Invalid fallback_type. Must be one of: {valid_fallback_types}"
|
||||
detail=f"Invalid fallback_type. Must be one of: {valid_fallback_types}",
|
||||
)
|
||||
|
||||
|
||||
fallbacks = get_all_fallbacks(
|
||||
model=model,
|
||||
llm_router=llm_router,
|
||||
fallback_type=effective_fallback_type
|
||||
fallback_type=effective_fallback_type,
|
||||
)
|
||||
metadata["fallbacks"] = fallbacks
|
||||
|
||||
|
||||
model_info["metadata"] = metadata
|
||||
|
||||
|
||||
model_data.append(model_info)
|
||||
|
||||
return dict(
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue