fix(proxy_server.py): working swagger on custom base

removes the swagger monkey patch - this seems to render the swagger on custom base paths
This commit is contained in:
Krrish Dholakia 2025-06-02 09:12:56 -07:00
parent 9630386f2b
commit 755ef77259
3 changed files with 56 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -740,7 +740,7 @@ origins = ["*"]
try:
current_dir = os.path.dirname(os.path.abspath(__file__))
ui_path = os.path.join(current_dir, "_experimental", "out")
app.mount("/ui", StaticFiles(directory=ui_path, html=True), name="ui")
router.mount("/ui", StaticFiles(directory=ui_path, html=True), name="ui")
# Iterate through files in the UI directory
for filename in os.listdir(ui_path):
if filename.endswith(".html") and filename != "index.html":
@ -787,20 +787,20 @@ app.add_middleware(
app.add_middleware(PrometheusAuthMiddleware)
swagger_path = os.path.join(current_dir, "swagger")
app.mount("/swagger", StaticFiles(directory=swagger_path), name="swagger")
router.mount("/swagger", StaticFiles(directory=swagger_path), name="swagger")
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",
)
# 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
# applications.get_swagger_ui_html = swagger_monkey_patch
from typing import Dict

View file

@ -0,0 +1,45 @@
import os
import sys
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
from litellm.proxy.proxy_server import app as litellm_app
# Create main FastAPI app
app = FastAPI(title="Custom LiteLLM Server")
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount LiteLLM app at /litellm
app.mount("/litellm", litellm_app)
# Default route at /
@app.get("/")
async def root():
return {"message": "Welcome to the API Gateway", "litellm_endpoint": "/litellm"}
# Health check endpoint
@app.get("/health")
async def health_check():
return {"status": "healthy"}
if __name__ == "__main__":
# Run the server on port 8000
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info")