-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (29 loc) · 839 Bytes
/
app.py
File metadata and controls
38 lines (29 loc) · 839 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
from fastapi import Request, FastAPI, HTTPException
from src.helper import chatbot
from fastapi.middleware.cors import CORSMiddleware
from typing import Optional
from pydantic import BaseModel
import traceback
class ChatBot(BaseModel):
query: str
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def hello():
return "Welcome to Science Chatbot"
@app.post("/chatbot")
def handler(body: ChatBot, request: Request):
try:
response = chatbot(body.query)
except:
print(dict(body))
print("Got some error in service")
print(traceback.format_exc())
raise HTTPException(status_code=500, detail="Got some error in service")
return {"response": response}