-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (25 loc) · 981 Bytes
/
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
from sqlalchemy import create_engine
from config import DATABASE_URL
from model_connector import generate_sql_from_nl, format_response
from sql_formatter import execute_sql, extract_db_schema
# Set up the database connection
if __name__ == "__main__":
engine = create_engine(DATABASE_URL)
schema_info = extract_db_schema(engine)
print("Ask a question about the database (type 'quit' to exit):")
while True:
user_input = input("User: ")
if user_input.lower() in ['quit', 'exit']:
break
try:
sql_query = generate_sql_from_nl(user_input, schema_info)
except Exception as e:
print("Error generating SQL:", str(e))
continue
try:
results = execute_sql(engine, sql_query)
except Exception as e:
print("Error executing SQL:", str(e))
continue
answer = format_response(results, sql_query)
print("Assistant:\n", answer)