-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_svs.py
75 lines (62 loc) · 2.26 KB
/
main_svs.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from cf_settings import *
from cf_db_model import DatabaseManager
from cf_llama_index_svs import LlamaIndexManager
import time
# Start here
print("Welcome! Let's get started...")
print("Reminder: 'ollama server' must be running in the background...")
### Start the Database ###
# Record the start time
start_time = time.time()
# Connect to the Database
print("Connecting to the database.")
db_manager = DatabaseManager(db_url)
# Record the end time
db_end_time = time.time()
# Calculate the elapsed time
elapsed_time = db_end_time - start_time
print(f"It took: {elapsed_time:.4f} seconds to get the Database started.\n")
### Create the LLM Query Engine ###
# db_manager: created above
# ollama_embedding_model, ollama_base_url, ollama_llm_model: pulled from cf_settings.py
print("Creating the LLM Query Engine.")
llama_index_manager = LlamaIndexManager(
db_manager = db_manager,
ollama_embedding_model = ollama_embedding_model,
ollama_base_url = ollama_base_url,
ollama_llm_model = ollama_llm_model,
dialect = dialect
)
query_engine = llama_index_manager.get_query_engine()
print("Query engine configured and ready to use.")
# Record the end time
llm_end_time = time.time()
# Calculate the elapsed time
elapsed_time = llm_end_time - db_end_time
print(f"It took: {elapsed_time:.4f} seconds to get the LLM Query engine started.\n")
### testing the LLM Query engine ###
print("How many tables are there in the database?")
response = query_engine.query("how many tables are there in the database")
print(response.response)
print("\n", response.metadata)
### Main Loop ###
while True:
user_query = input("\nEnter your query (type /q to quit): ")
if user_query == "/q":
print("Quiting...")
break
else:
# Record the start time
start_time = time.time()
print("\nGetting your answer...")
response = query_engine.query(user_query)
print(response.response)
print("\nHere's the SQL query used:")
print(response.metadata)
# Record the end time
end_time = time.time()
# Calculate the elapsed time
elapsed_time = end_time - start_time
print(f"It took: {elapsed_time:.4f} seconds to get your answer.\n")
### The end ###
print("The program ends here. Goodbye.")