-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (52 loc) · 1.96 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import os
from queries_core import QueriesCore
from visual.ascii_table import csv_string_to_ascii_table
from visual.ansi_colors import COLOR
from visual.sql_formatter import SQLFormatter
def clear_screen():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
if __name__ == "__main__":
clear_screen()
with open('examples/prompts.json', 'r') as file:
data = json.load(file)
prompts = data['prompts']
try:
queries_core = QueriesCore()
sql_formatter = SQLFormatter()
except Exception as e:
print(f"{COLOR["red"]}ERROR{COLOR["reset"]}: {COLOR["yellow"]}{e}{COLOR["reset"]}\n")
exit()
if prompts == []:
prompts.append(input("Write your prompt here:\n\n"))
clear_screen()
answers = []
for prompt in prompts:
result = {}
try:
print(f"\n{COLOR["bg_bright_black"]}#########################################################################################\n{COLOR["reset"]}")
print(f"{COLOR["yellow"]}PROMPT{COLOR["reset"]}: {COLOR["cyan"]}{prompt}{COLOR["reset"]}")
print("Processing...")
csv, query = queries_core.answer_user_prompt(prompt)
result = {
"prompt": prompt,
"query": query,
"csv": csv
}
table = csv_string_to_ascii_table(csv, "blue", "green", "green")
print("\033[F\033[K", end='')
print(f"\n{table}")
print(f"\n{COLOR["yellow"]}GENERATED SQL QUERY{COLOR["reset"]}:")
sql_formatter.format_sql(query)
except Exception as e:
result = {
"prompt": prompt,
"error": e
}
print(f"{COLOR["red"]}ERROR{COLOR["reset"]}: {COLOR["yellow"]}{e}{COLOR["reset"]}")
answers.append(result)
with open('examples/answers.json', 'w') as file:
json.dump(answers, file, indent=4)