-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatbot.py
More file actions
31 lines (26 loc) · 1.35 KB
/
Chatbot.py
File metadata and controls
31 lines (26 loc) · 1.35 KB
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
from ChatBotHelper.executeSQLQuery import execute_sql_query
from ChatBotHelper.generateSQLQuery import generate_sql_query
from ChatBotHelper.QueryClassifier import classify_query
from ChatBotHelper.GeneralResponse import genericResponse
def chatbot(supabase, memory, llm, schemaContext, sqlPromptTemplate, formatType = "markdown", DEBUG_MODE = False):
"""Main chatbot loop"""
print("Supabase Chatbot (type 'exit' to stop)")
while True:
user_input = input("\nYou: ")
if user_input.lower() == "exit":
print("Goodbye!")
break
queryType = classify_query(user_input, llm)
if queryType == "sql_generation":
sql_query = generate_sql_query(user_input, llm, schemaContext, sqlPromptTemplate, memory)
result = execute_sql_query(sql_query, llm, supabase, formatType)
print(f"\n{result}\n")
# Save last query & result
#last_sql_query = sql_query # Track last executed SQL query
memory.save_context({"input": f"SQL: {sql_query}"}, {"output": result})
elif queryType == "general_response":
result = genericResponse(user_input, llm, memory)
print(f"\n{result}\n")
if DEBUG_MODE:
if queryType == "sql_generation":
print(f"\nGenerated SQL:\n{sql_query}\n") # Only show if debugging