-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
40 lines (30 loc) · 865 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
32
33
34
35
36
37
38
39
import time
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from dotenv import load_dotenv
from app import livepeer_swarm
load_dotenv()
app = FastAPI()
origins = [
"http://localhost:8000",
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class ChatRequest(BaseModel):
prompt: str
@app.post("/chat/")
async def chat(request: ChatRequest):
try:
if request.prompt.lower() == "exit":
return {"response": "Hope you're enjoy, see you!"}
video_id = await livepeer_swarm.chat(request.prompt)
return {"video_id": video_id}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))