forked from theroyallab/tabbyAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes the API more modular for other API implementations in the future. Signed-off-by: kingbri <bdashore3@proton.me>
- Loading branch information
Showing
3 changed files
with
74 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import uvicorn | ||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from loguru import logger | ||
|
||
from common.logger import UVICORN_LOG_CONFIG | ||
from endpoints.OAI.router import router as OAIRouter | ||
|
||
app = FastAPI( | ||
title="TabbyAPI", | ||
summary="An OAI compatible exllamav2 API that's both lightweight and fast", | ||
description=( | ||
"This docs page is not meant to send requests! Please use a service " | ||
"like Postman or a frontend UI." | ||
), | ||
) | ||
|
||
# ALlow CORS requests | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
|
||
async def start_api(host: str, port: int): | ||
"""Isolated function to start the API server""" | ||
|
||
# TODO: Move OAI API to a separate folder | ||
logger.info(f"Developer documentation: http://{host}:{port}/redoc") | ||
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) | ||
|
||
config = uvicorn.Config( | ||
app, | ||
host=host, | ||
port=port, | ||
log_config=UVICORN_LOG_CONFIG, | ||
) | ||
server = uvicorn.Server(config) | ||
|
||
await server.serve() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters