Rauhan commited on
Commit
7d859ca
·
1 Parent(s): a383d87

UPDATE: QnA Functionality

Browse files
Files changed (2) hide show
  1. app.py +24 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -3,6 +3,7 @@ from functions import *
3
  from PyPDF2 import PdfReader
4
  import pandas as pd
5
  from fastapi import FastAPI, File, UploadFile
 
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from langchain_community.document_loaders import UnstructuredURLLoader
8
 
@@ -71,6 +72,29 @@ async def addText(vectorstore: str, text: str):
71
  }
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  @app.post("/addWebsite")
75
  async def addWebsite(vectorstore: str, websiteUrls: list[str]):
76
  urls = websiteUrls
 
3
  from PyPDF2 import PdfReader
4
  import pandas as pd
5
  from fastapi import FastAPI, File, UploadFile
6
+ from pydantic import BaseModel
7
  from fastapi.middleware.cors import CORSMiddleware
8
  from langchain_community.document_loaders import UnstructuredURLLoader
9
 
 
72
  }
73
 
74
 
75
+
76
+ class AddQAPair(BaseModel):
77
+ vectorstore: str
78
+ question: str
79
+ answer: str
80
+
81
+
82
+ @app.post("/addQAPair")
83
+ async def addText(addQaPair: AddQAPair):
84
+ username, chatbotname = addQaPair.vectorstore.split("-")[1], addQaPair.vectorstore.split("-")[2]
85
+ df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
86
+ currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
87
+ qa = f"QUESTION: {addQaPair.question}\tANSWER: {addQaPair.answer}"
88
+ newCount = currentCount + len(qa)
89
+ if newCount < 400000:
90
+ client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
91
+ return addDocuments(text = qa, vectorstore = addQaPair.vectorstore)
92
+ else:
93
+ return {
94
+ "output": "WEBSITE EXCEEDING LIMITS, PLEASE TRY WITH A SMALLER DOCUMENT."
95
+ }
96
+
97
+
98
  @app.post("/addWebsite")
99
  async def addWebsite(vectorstore: str, websiteUrls: list[str]):
100
  urls = websiteUrls
requirements.txt CHANGED
@@ -14,6 +14,7 @@ langsmith
14
  lxml
15
  PyPDF2
16
  python-dotenv
 
17
  pandas
18
  sentence-transformers
19
  supabase
 
14
  lxml
15
  PyPDF2
16
  python-dotenv
17
+ pydantic
18
  pandas
19
  sentence-transformers
20
  supabase