-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
45 lines (32 loc) · 821 Bytes
/
api.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
40
41
42
43
44
45
from fastapi import FastAPI
import uvicorn
import get_prediction
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
app = FastAPI()
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class Chat(BaseModel):
text: str
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/chat-response")
def predict(chat: Chat):
print(chat.text)
return get_prediction.get_completion(chat.text)
if __name__ == '__main__':
uvicorn.run(app, host='localhost', port=8000)
# 3. Run the API
# uvicorn get_prediction:app --reload