-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (32 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from src.embedder import Embedder
from src.assistant import Assistant
from src.constants import DEMO_COLLECTION_NAME
def index_documents():
# read all text files in the documents folder
for file_name in os.listdir("./documents"):
with open(f"./documents/{file_name}", "r") as f:
text = f.read()
print(f"Indexing document: {file_name}")
Embedder().embed_information(
collection=DEMO_COLLECTION_NAME,
text=text,
name=file_name,
)
def query_documents():
while True:
question = input("\n\nAsk a question, (Type 'exit' to exit).\n\nQuestion: ")
if question.lower().strip() == "exit":
break
answer = Assistant().get_answer(question=question)
print(f"Answer: {answer}")
print("\n\n\n")
def main():
print("\n\nWhat would you like to do?\n1. Index documents\n2. Query documents")
choice = input("Enter your choice: ")
if choice == "1":
index_documents()
elif choice == "2":
query_documents()
if __name__ == "__main__":
main()