From 90f64e2527c99e5bc9cb8845543c53285eb03d3a Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 9 Sep 2024 20:22:03 +0100 Subject: [PATCH] fix: references on shar / api keys --- application/api/answer/routes.py | 15 ------------- application/api/user/routes.py | 36 +++++--------------------------- 2 files changed, 5 insertions(+), 46 deletions(-) diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index de9b8bb3..15feeb3c 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -98,21 +98,6 @@ def get_retriever(source_id: str): return retriever_name -def get_vectorstore(data): - if "active_docs" in data: - if data["active_docs"].split("/")[0] == "default": - vectorstore = "" - elif data["active_docs"].split("/")[0] == "local": - vectorstore = "indexes/" + data["active_docs"] - else: - vectorstore = "vectors/" + data["active_docs"] - if data["active_docs"] == "default": - vectorstore = "" - else: - vectorstore = "" - vectorstore = os.path.join("application", vectorstore) - return vectorstore - def is_azure_configured(): return settings.OPENAI_API_BASE and settings.OPENAI_API_VERSION and settings.AZURE_DEPLOYMENT_NAME diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 5ac6e741..e6e0cb7d 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -286,39 +286,13 @@ def combined_json(): @user.route("/api/docs_check", methods=["POST"]) def check_docs(): - # check if docs exist in a vectorstore folder data = request.get_json() - # split docs on / and take first part - if data["docs"].split("/")[0] == "local": - return {"status": "exists"} + vectorstore = "vectors/" + secure_filename(data["docs"]) - base_path = "https://raw.githubusercontent.com/arc53/DocsHUB/main/" if os.path.exists(vectorstore) or data["docs"] == "default": return {"status": "exists"} else: - file_url = urlparse(base_path + vectorstore + "index.faiss") - - if ( - file_url.scheme in ["https"] - and file_url.netloc == "raw.githubusercontent.com" - and file_url.path.startswith("/arc53/DocsHUB/main/") - ): - r = requests.get(file_url.geturl()) - if r.status_code != 200: - return {"status": "null"} - else: - if not os.path.exists(vectorstore): - os.makedirs(vectorstore) - with open(vectorstore + "index.faiss", "wb") as f: - f.write(r.content) - - r = requests.get(base_path + vectorstore + "index.pkl") - with open(vectorstore + "index.pkl", "wb") as f: - f.write(r.content) - else: - return {"status": "null"} - - return {"status": "loaded"} + return {"status": "not found"} @user.route("/api/create_prompt", methods=["POST"]) @@ -445,7 +419,7 @@ def create_api_key(): "chunks": chunks, } if "source" in data and ObjectId.is_valid(data["source"]): - new_api_key["source"] = DBRef("vectors", ObjectId(data["source"])) + new_api_key["source"] = DBRef("sources", ObjectId(data["source"])) if "retriever" in data: new_api_key["retriever"] = data["retriever"] resp = api_key_collection.insert_one(new_api_key) @@ -494,7 +468,7 @@ def share_conversation(): "user": user, } if "source" in data and ObjectId.is_valid(data["source"]): - new_api_key_data["source"] = DBRef("vectors",ObjectId(data["source"])) + new_api_key_data["source"] = DBRef("sources",ObjectId(data["source"])) elif "retriever" in data: new_api_key_data["retriever"] = data["retriever"] @@ -543,7 +517,7 @@ def share_conversation(): new_api_key_data["key"] = api_uuid new_api_key_data["name"] = name if "source" in data and ObjectId.is_valid(data["source"]): - new_api_key_data["source"] = DBRef("vectors", ObjectId(data["source"])) + new_api_key_data["source"] = DBRef("sources", ObjectId(data["source"])) if "retriever" in data: new_api_key_data["retriever"] = data["retriever"] api_key_collection.insert_one(new_api_key_data)