arcsu1's picture
update
b64d09e
raw
history blame
897 Bytes
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import chatbot
app = FastAPI()
model = None
# Add CORS middleware to allow any origin
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods (GET, POST, etc.)
allow_headers=["*"], # Allows all headers
)
@app.get("/")
def root():
return "Hello World"
# Define the Pydantic model to parse JSON input
from pydantic import BaseModel
class HistoryRequest(BaseModel):
user: list[str]
ai: list[str]
@app.post("/generate")
def generate_response(history: HistoryRequest):
try:
model
except:
model = chatbot.ChatBot()
if type(model) != type(chatbot.ChatBot()):
model = chatbot.ChatBot()
response = model.generate_response(history)
return response