File size: 2,149 Bytes
0dda2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfd2b5e
 
 
 
 
0dda2a1
 
 
 
 
cfd2b5e
 
 
 
0dda2a1
 
 
40d15f0
 
 
0dda2a1
 
 
 
 
 
40d15f0
cfd2b5e
 
 
 
 
 
 
 
 
 
0dda2a1
 
 
 
 
40d15f0
 
cfd2b5e
 
 
0dda2a1
 
 
 
8f8a88e
cfd2b5e
 
 
 
 
40d15f0
 
 
 
cfd2b5e
 
 
 
40d15f0
 
 
 
 
cfd2b5e
 
 
 
 
40d15f0
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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)
    output = {
        "output": response
    }

    return output


@app.post("/login")
async def login(username: str, password: str):
    response = matchPassword(username = username, password = password)
    output = {
        "output": response
    }
    return output


@app.get("/newChatbot/{chatbotName}")
async def newChatbot(chatbotName: str):
    createTable(tablename = chatbotName)
    return {
        "output": "SUCCESS"
    }


@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()
    addDocuments(text = text, vectorstore = vectorstore)
    output = {
        "output": "SUCCESS"
    }

    return output



@app.post("/addText")
async def addText(vectorstore: str, text: str):
    addDocuments(text = text, vectorstore = vectorstore)
    output = {
        "output": "SUCCESS"
    }
    return output


@app.get("/answerQuery")
async def answerQuestion(query: str, vectorstore: str, llmModel: str = "llama3-70b-8192"):
    response = answerQuery(query=query, vectorstore=vectorstore, llmModel=llmModel)
    output = {
        "output": response
    }

    return output

@app.get("/deleteChatbot/{chatbotName}")
async def delete(chatbotName: str):
    deleteTable(tableName=chatbotName)
    response = {
        "output": "SUCCESS"
    }
    return response


@app.get("/listChatbots/{username}")
async def delete(username: str):
    chatbots = listTables(username=username)
    response = {
        "output": chatbots
    }

    return response