Rauhan commited on
Commit
6187b6c
1 Parent(s): 2d84492

UPDATE: New Endpoints

Browse files
Files changed (2) hide show
  1. app.py +14 -4
  2. functions.py +2 -5
app.py CHANGED
@@ -32,6 +32,12 @@ async def login(username: str, password: str):
32
 
33
  @app.post("/newChatbot")
34
  async def newChatbot(chatbotName: str, username: str):
 
 
 
 
 
 
35
  client.table("ConversAI_ChatbotInfo").insert({"username": username, "chatbotname": chatbotName}).execute()
36
  chatbotName = f"convai-{username}-{chatbotName}"
37
  return createTable(tablename = chatbotName)
@@ -47,8 +53,9 @@ async def addPDFData(vectorstore: str, pdf: UploadFile = File(...)):
47
  username, chatbotname = vectorstore.split("-")[1], vectorstore.split("-")[2]
48
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
49
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
 
50
  newCount = currentCount + len(text)
51
- if newCount < 1000000:
52
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
53
  return addDocuments(text = text, vectorstore = vectorstore)
54
  else:
@@ -63,7 +70,8 @@ async def addText(vectorstore: str, text: str):
63
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
64
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
65
  newCount = currentCount + len(text)
66
- if newCount < 1000000:
 
67
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
68
  return addDocuments(text = text, vectorstore = vectorstore)
69
  else:
@@ -86,7 +94,8 @@ async def addText(addQaPair: AddQAPair):
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 < 1000000:
 
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:
@@ -105,7 +114,8 @@ async def addWebsite(vectorstore: str, websiteUrls: list[str]):
105
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
106
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
107
  newCount = currentCount + len(text)
108
- if newCount < 1000000:
 
109
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
110
  return addDocuments(text = text, vectorstore = vectorstore)
111
  else:
 
32
 
33
  @app.post("/newChatbot")
34
  async def newChatbot(chatbotName: str, username: str):
35
+ currentBotCount = listTables(username = username)
36
+ limit = client.table("ConversAI_UserConfig").select("chatbotLimit").eq("username", "rauhan").execute().data[0]["chatbotLimit"]
37
+ if currentBotCount < limit:
38
+ return {
39
+ "output": "CHATBOT LIMIT EXCEEDED"
40
+ }
41
  client.table("ConversAI_ChatbotInfo").insert({"username": username, "chatbotname": chatbotName}).execute()
42
  chatbotName = f"convai-{username}-{chatbotName}"
43
  return createTable(tablename = chatbotName)
 
53
  username, chatbotname = vectorstore.split("-")[1], vectorstore.split("-")[2]
54
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
55
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
56
+ limit = client.table("ConversAI_UserConfig").select("tokenLimit").eq("username", username).execute().data[0]["tokenLimit"]
57
  newCount = currentCount + len(text)
58
+ if newCount < int(limit):
59
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
60
  return addDocuments(text = text, vectorstore = vectorstore)
61
  else:
 
70
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
71
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
72
  newCount = currentCount + len(text)
73
+ limit = client.table("ConversAI_UserConfig").select("tokenLimit").eq("username", username).execute().data[0]["tokenLimit"]
74
+ if newCount < int(limit):
75
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
76
  return addDocuments(text = text, vectorstore = vectorstore)
77
  else:
 
94
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
95
  qa = f"QUESTION: {addQaPair.question}\tANSWER: {addQaPair.answer}"
96
  newCount = currentCount + len(qa)
97
+ limit = client.table("ConversAI_UserConfig").select("tokenLimit").eq("username", username).execute().data[0]["tokenLimit"]
98
+ if newCount < int(limit):
99
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
100
  return addDocuments(text = qa, vectorstore = addQaPair.vectorstore)
101
  else:
 
114
  df = pd.DataFrame(client.table("ConversAI_ChatbotInfo").select("*").execute().data)
115
  currentCount = df[(df["username"] == username) & (df["chatbotname"] == chatbotname)]["charactercount"].iloc[0]
116
  newCount = currentCount + len(text)
117
+ limit = client.table("ConversAI_UserConfig").select("tokenLimit").eq("username", username).execute().data[0]["tokenLimit"]
118
+ if newCount < int(limit):
119
  client.table("ConversAI_ChatbotInfo").update({"charactercount": str(newCount)}).eq("username", username).eq("chatbotname", chatbotname).execute()
120
  return addDocuments(text = text, vectorstore = vectorstore)
121
  else:
functions.py CHANGED
@@ -78,11 +78,8 @@ def createUser(username: str, password: str) -> None:
78
  try:
79
  userData = client.table("ConversAI_UserInfo").select("*").execute().data
80
  if username not in [userData[x]["username"] for x in range(len(userData))]:
81
- response = (
82
- client.table("ConversAI_UserInfo")
83
- .insert({"username": username, "password": password})
84
- .execute()
85
- )
86
  return {
87
  "output": "SUCCESS"
88
  }
 
78
  try:
79
  userData = client.table("ConversAI_UserInfo").select("*").execute().data
80
  if username not in [userData[x]["username"] for x in range(len(userData))]:
81
+ client.table("ConversAI_UserInfo").insert({"username": username, "password": password}).execute()
82
+ client.table("ConversAI_UserConfig").insert({"username": username}).execute()
 
 
 
83
  return {
84
  "output": "SUCCESS"
85
  }