-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (54 loc) · 2.24 KB
/
Copy pathmain.py
File metadata and controls
72 lines (54 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""FastAPI assembly for the live gateway.
Protocol behavior lives in the mounted routers:
- `/v1/*` for OpenAI-compatible chat/models and the universal/task API
- `/config/*` for admin/config management
This module only wires those routers together and serves the lightweight static
UI entrypoints (`/`, `/chat`, `/config`).
"""
from fastapi import FastAPI, Request, Response
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from pathlib import Path
from .server.routes import router as api_router
from .server.config_routes import router as config_router
from .server.anthropic_routes import router as anthropic_router
app = FastAPI(
title="Open LLM Auth",
description="LLM gateway with OpenAI-compatible chat and universal task APIs",
)
# API routes: chat/models plus the universal task surface.
app.include_router(api_router)
app.include_router(anthropic_router)
app.include_router(config_router)
# Static files back the lightweight config/chat GUIs.
static_dir = Path(__file__).parent / "server" / "static"
if static_dir.exists():
app.mount("/static", StaticFiles(directory=str(static_dir)), name="static")
# Templates for the advanced admin dashboard.
templates_dir = Path(__file__).parent / "server" / "templates"
templates = Jinja2Templates(directory=str(templates_dir))
@app.get("/health")
def health_check():
return {"status": "ok"}
@app.get("/")
def root(request: Request):
"""Serve the advanced admin dashboard."""
dashboard_file = templates_dir / "dashboard.html"
if dashboard_file.exists():
return templates.TemplateResponse(request, "dashboard.html")
index_file = static_dir / "index.html"
if index_file.exists():
return FileResponse(str(index_file))
return {"message": "Open LLM Auth API", "docs": "/docs", "gui": "/config"}
@app.head("/")
def root_head():
"""Claude Code probes the base URL with HEAD; respond cleanly."""
return Response(status_code=200)
@app.get("/chat")
def chat_gui():
"""Serve the browser chat UI when static assets are present."""
chat_file = static_dir / "chat.html"
if chat_file.exists():
return FileResponse(str(chat_file))
return {"error": "Chat GUI not found"}