File size: 535 Bytes
021b3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from chat import query_chatbot_with_prompt, load_model

app = FastAPI()

class QueryRequest(BaseModel):
    question: str

@app.on_event("startup")
async def startup_event():
    load_model()

@app.post("/query/")
async def query_chatbot(request: QueryRequest):
    response = query_chatbot_with_prompt(request.question)
    if not response:
        raise HTTPException(status_code=500, detail="No response from the chatbot")
    return {"response": response}