-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (25 loc) · 878 Bytes
/
main.py
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
from fastapi import FastAPI, APIRouter
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
import uvicorn
from app.prompt import prompt
class PromptRequest(BaseModel):
prompt: str
# serving static files
app = FastAPI()
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
@app.get("/")
async def read_index():
return FileResponse("static/index.html")
# setting up API router
api_router = APIRouter()
# this endpoint responds to get requests from "/api/example"
@api_router.post("/prompt")
async def prompt_api(req: PromptRequest):
response = prompt(req.prompt)
return {"message": response}
# adding /api/ prefix to all api_router decorators
app.include_router(api_router, prefix="/api")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)