API: Add standalone method to fetch OpenAPI docs

Generates and stores an export of the openapi.json file for use in
static websites.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-07-07 21:34:18 -04:00
parent bb8b02a60a
commit 5e82b7eb69
3 changed files with 22 additions and 2 deletions

3
.gitignore vendored
View file

@ -199,3 +199,6 @@ sampler_overrides/*
# Gpu lib preferences file
gpu_lib.txt
# OpenAPI JSON
openapi.json

View file

@ -25,6 +25,10 @@ app.add_middleware(
)
def setup_app():
app.include_router(OAIRouter)
async def start_api(host: str, port: int):
"""Isolated function to start the API server"""
@ -33,8 +37,8 @@ async def start_api(host: str, port: int):
logger.info(f"Completions: http://{host}:{port}/v1/completions")
logger.info(f"Chat completions: http://{host}:{port}/v1/chat/completions")
# Add OAI router
app.include_router(OAIRouter)
# Setup app
setup_app()
config = uvicorn.Config(
app,

13
generate_openapi.py Normal file
View file

@ -0,0 +1,13 @@
import json
from endpoints import server
if __name__ == "__main__":
"""Uses the FastAPI server to write an OpenAPI JSON documentation file."""
server.setup_app()
openapi_json = json.dumps(server.app.openapi())
# Write JSON to a file
with open("openapi.json", "w") as f:
f.write(openapi_json)