path handling

This commit is contained in:
Alex
2023-02-20 00:10:04 +00:00
parent 63859a814b
commit 8819f9360b
3 changed files with 13 additions and 12 deletions

View File

@@ -147,18 +147,19 @@ def check_docs():
data = request.get_json() data = request.get_json()
vectorstore = "vectors/" + data["docs"] vectorstore = "vectors/" + data["docs"]
base_path = 'https://raw.githubusercontent.com/arc53/DocsHUB/main/' base_path = 'https://raw.githubusercontent.com/arc53/DocsHUB/main/'
# if os.path.exists(vectorstore) or data["docs"] == "default":
if os.path.exists(vectorstore):
return {"status": 'exists'} return {"status": 'exists'}
else: else:
r = requests.get(base_path + vectorstore + "index.faiss") r = requests.get(base_path + vectorstore + "index.faiss")
# save to vectors directory
# check if the directory exists if r.status_code != 200:
return {"status": 'null'}
else:
if not os.path.exists(vectorstore): if not os.path.exists(vectorstore):
os.makedirs(vectorstore) os.makedirs(vectorstore)
with open(vectorstore + "index.faiss", "wb") as f: with open(vectorstore + "index.faiss", "wb") as f:
f.write(r.content) f.write(r.content)
# download the store # download the store
r = requests.get(base_path + vectorstore + "index.pkl") r = requests.get(base_path + vectorstore + "index.pkl")
with open(vectorstore + "index.pkl", "wb") as f: with open(vectorstore + "index.pkl", "wb") as f:

Binary file not shown.

Binary file not shown.