ConversAI / app.py
Rauhan's picture
UPDATE: QDRANT
681223f
raw
history blame
1.72 kB
import io
from functions import *
from PyPDF2 import PdfReader
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI(title = "ConversAI", root_path = "/api/v1")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/signup")
async def signup(username: str, password: str):
response = createUser(username = username, password = password)
return response
@app.post("/login")
async def login(username: str, password: str):
response = matchPassword(username = username, password = password)
return response
@app.post("/newChatbot")
async def newChatbot(chatbotName: str, username: str):
chatbotName = f"convai-{username}-{chatbotName}"
return createTable(tablename = chatbotName)
@app.post("/addPDF")
async def addPDFData(vectorstore: str, pdf: UploadFile = File(...)):
pdf = await pdf.read()
reader = PdfReader(io.BytesIO(pdf))
text = ""
for page in reader.pages:
text += page.extract_text()
return addDocuments(text = text, vectorstore = vectorstore)
@app.post("/addText")
async def addText(vectorstore: str, text: str):
return addDocuments(text = text, vectorstore = vectorstore)
@app.post("/answerQuery")
async def answerQuestion(query: str, vectorstore: str, llmModel: str = "llama3-70b-8192"):
return answerQuery(query=query, vectorstore=vectorstore, llmModel=llmModel)
@app.post("/deleteChatbot")
async def delete(chatbotName: str):
return deleteTable(tableName=chatbotName)
@app.post("/listChatbots")
async def delete(username: str):
return listTables(username=username)