Merge pull request #85 from mefengl/fix

fix: restore index back when continue process
pull/88/head
Alex 2 years ago committed by GitHub
commit a61fd87783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,11 +32,14 @@ def call_openai_api(docs):
print("Saving progress") print("Saving progress")
print(f"stopped at {c1} out of {len(docs)}") print(f"stopped at {c1} out of {len(docs)}")
faiss.write_index(store.index, "docs.index") faiss.write_index(store.index, "docs.index")
store_index_bak = store.index
store.index = None store.index = None
with open("faiss_store.pkl", "wb") as f: with open("faiss_store.pkl", "wb") as f:
pickle.dump(store, f) pickle.dump(store, f)
print("Sleeping for 10 seconds and trying again") print("Sleeping for 60 seconds and trying again")
time.sleep(10) time.sleep(60)
faiss.write_index(store_index_bak, "docs.index")
store.index = store_index_bak
store.add_texts([i.page_content], metadatas=[i.metadata]) store.add_texts([i.page_content], metadatas=[i.metadata])
c1 += 1 c1 += 1
@ -66,4 +69,4 @@ def get_user_permission(docs):
elif user_input == "": elif user_input == "":
call_openai_api(docs) call_openai_api(docs)
else: else:
print("The API was not called. No money was spent.") print("The API was not called. No money was spent.")

Loading…
Cancel
Save