Spaces:
Sleeping
Sleeping
update functions.py
Browse files- app.py +22 -9
- functions.py +6 -6
app.py
CHANGED
|
@@ -265,7 +265,7 @@ async def loadPDF(vectorstore: str, pdf: UploadFile = File(...)):
|
|
| 265 |
"source": source
|
| 266 |
}
|
| 267 |
numTokens = len(" ".join([text[x] for x in text]).translate(str.maketrans('', '', string.punctuation)).split(" "))
|
| 268 |
-
dct = json.dumps(dct, indent=1).encode("utf-8")
|
| 269 |
fileName = createDataSourceName(sourceName=source)
|
| 270 |
response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
|
| 271 |
response = (
|
|
@@ -559,7 +559,7 @@ async def loadEditedJson(loadEditedJsonConfig: LoadEditedJson):
|
|
| 559 |
username, chatbotName = loadEditedJsonConfig.vectorstore.split("$")[1], loadEditedJsonConfig.vectorstore.split("$")[2]
|
| 560 |
trackUsage(vectorstore=loadEditedJsonConfig.vectorstore, endpoint="/loadEditedJson")
|
| 561 |
jsonData = decodeBase64(loadEditedJsonConfig.jsonData)
|
| 562 |
-
jsonData = json.dumps(jsonData, indent = 1).encode("utf-8")
|
| 563 |
fileName = createDataSourceName(loadEditedJsonConfig.dataSourceName)
|
| 564 |
response = supabase.storage.from_("ConversAI").upload(file=jsonData, path=f"{fileName}_data.json")
|
| 565 |
response = (
|
|
@@ -578,19 +578,32 @@ async def loadEditedJson(loadEditedJsonConfig: LoadEditedJson):
|
|
| 578 |
|
| 579 |
|
| 580 |
@app.post("/publicOrPrivate")
|
| 581 |
-
async def publicOrPrivate(vectorstore: str, mode: str =
|
| 582 |
trackUsage(vectorstore=vectorstore, endpoint="/publicOrPrivate")
|
| 583 |
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 584 |
-
|
|
|
|
| 585 |
supabase.table("ConversAI_ChatbotInfo")
|
| 586 |
-
.
|
| 587 |
.eq("user_id", username)
|
| 588 |
.eq("chatbotname", chatbotName)
|
| 589 |
.execute()
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 594 |
|
| 595 |
|
| 596 |
|
|
|
|
| 265 |
"source": source
|
| 266 |
}
|
| 267 |
numTokens = len(" ".join([text[x] for x in text]).translate(str.maketrans('', '', string.punctuation)).split(" "))
|
| 268 |
+
dct = json.dumps(dct, indent=1).encode("utf-8", errors = "replace")
|
| 269 |
fileName = createDataSourceName(sourceName=source)
|
| 270 |
response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
|
| 271 |
response = (
|
|
|
|
| 559 |
username, chatbotName = loadEditedJsonConfig.vectorstore.split("$")[1], loadEditedJsonConfig.vectorstore.split("$")[2]
|
| 560 |
trackUsage(vectorstore=loadEditedJsonConfig.vectorstore, endpoint="/loadEditedJson")
|
| 561 |
jsonData = decodeBase64(loadEditedJsonConfig.jsonData)
|
| 562 |
+
jsonData = json.dumps(jsonData, indent = 1).encode("utf-8", errors = "replace")
|
| 563 |
fileName = createDataSourceName(loadEditedJsonConfig.dataSourceName)
|
| 564 |
response = supabase.storage.from_("ConversAI").upload(file=jsonData, path=f"{fileName}_data.json")
|
| 565 |
response = (
|
|
|
|
| 578 |
|
| 579 |
|
| 580 |
@app.post("/publicOrPrivate")
|
| 581 |
+
async def publicOrPrivate(vectorstore: str, mode: str | None = None):
|
| 582 |
trackUsage(vectorstore=vectorstore, endpoint="/publicOrPrivate")
|
| 583 |
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 584 |
+
if mode == None:
|
| 585 |
+
value = (
|
| 586 |
supabase.table("ConversAI_ChatbotInfo")
|
| 587 |
+
.select("isPrivate")
|
| 588 |
.eq("user_id", username)
|
| 589 |
.eq("chatbotname", chatbotName)
|
| 590 |
.execute()
|
| 591 |
+
)
|
| 592 |
+
value = value.data[0]["isPrivate"]
|
| 593 |
+
return {
|
| 594 |
+
"output": value
|
| 595 |
+
}
|
| 596 |
+
else:
|
| 597 |
+
response = (
|
| 598 |
+
supabase.table("ConversAI_ChatbotInfo")
|
| 599 |
+
.update({"isPrivate": mode})
|
| 600 |
+
.eq("user_id", username)
|
| 601 |
+
.eq("chatbotname", chatbotName)
|
| 602 |
+
.execute()
|
| 603 |
+
)
|
| 604 |
+
return {
|
| 605 |
+
"output": "SUCCESS"
|
| 606 |
+
}
|
| 607 |
|
| 608 |
|
| 609 |
|
functions.py
CHANGED
|
@@ -359,18 +359,18 @@ def extractTextFromUrlList(urls):
|
|
| 359 |
def encodeToBase64(dct: dict):
|
| 360 |
for key in dct:
|
| 361 |
if type(dct[key]) == str:
|
| 362 |
-
dct[key] = base64.b64encode(dct[key].encode("utf-8")).decode("utf-8")
|
| 363 |
elif type(dct[key]) == dict:
|
| 364 |
dct[key] = encodeToBase64(dct[key])
|
| 365 |
return dct
|
| 366 |
|
| 367 |
|
| 368 |
def decodeBase64(dct: dict):
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
dct[key] =
|
| 374 |
return dct
|
| 375 |
|
| 376 |
|
|
|
|
| 359 |
def encodeToBase64(dct: dict):
|
| 360 |
for key in dct:
|
| 361 |
if type(dct[key]) == str:
|
| 362 |
+
dct[key] = base64.b64encode(dct[key].encode("utf-8")).decode("utf-8", errors = "replace")
|
| 363 |
elif type(dct[key]) == dict:
|
| 364 |
dct[key] = encodeToBase64(dct[key])
|
| 365 |
return dct
|
| 366 |
|
| 367 |
|
| 368 |
def decodeBase64(dct: dict):
|
| 369 |
+
if type(dct["output"]) == str:
|
| 370 |
+
dct["output"] = base64.b64decode(dct["output"].encode("utf-8")).decode("utf-8", errors = "replace")
|
| 371 |
+
else:
|
| 372 |
+
for key in dct["output"]:
|
| 373 |
+
dct["output"][key] = base64.b64decode(dct["output"][key].encode("utf-8")).decode("utf-8", errors = "replace")
|
| 374 |
return dct
|
| 375 |
|
| 376 |
|