-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (26 loc) · 1013 Bytes
/
main.py
File metadata and controls
39 lines (26 loc) · 1013 Bytes
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from models import AgentReq, HealthRes, TodoStage
from service import get_suggest_res, get_todo_res, get_week_plan_res
app = FastAPI(title="Sloth AI Agent API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/health", response_model=HealthRes)
def get_health() -> HealthRes:
return HealthRes(status="ok")
@app.post("/suggest", response_model=list[str])
def get_suggest(req: AgentReq) -> list[str]:
return get_suggest_res(req.contents).root
@app.post("/writ", response_model=list[str])
def get_write(req: AgentReq) -> list[str]:
return get_week_plan_res(req.contents).root
@app.post("/todo", response_model=list[TodoStage])
def get_todo(req: AgentReq) -> list[TodoStage]:
return get_todo_res(req.contents).root
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=False)