Spaces:
Sleeping
Sleeping
alejandro
commited on
Commit
·
411b037
1
Parent(s):
e37ebd7
feat: enable history
Browse files- src/app.py +14 -2
src/app.py
CHANGED
@@ -42,6 +42,7 @@ def get_response(user_query, chat_history, db):
|
|
42 |
Based on the table schema below, question, sql query, and sql response, write a natural language response:
|
43 |
{schema}
|
44 |
|
|
|
45 |
Question: {question}
|
46 |
SQL Query: {query}
|
47 |
SQL Response: {response}"""
|
@@ -64,7 +65,8 @@ def get_response(user_query, chat_history, db):
|
|
64 |
)
|
65 |
|
66 |
return chain.stream({
|
67 |
-
"question": user_query
|
|
|
68 |
})
|
69 |
|
70 |
load_dotenv()
|
@@ -73,7 +75,7 @@ st.set_page_config(initial_sidebar_state="expanded", page_title="Chat with a MyS
|
|
73 |
|
74 |
if 'chat_history' not in st.session_state:
|
75 |
st.session_state.chat_history = [
|
76 |
-
AIMessage(content="")
|
77 |
]
|
78 |
|
79 |
if 'db' not in st.session_state:
|
@@ -103,6 +105,16 @@ with st.sidebar:
|
|
103 |
|
104 |
user_query = st.chat_input("Type a message...")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
if user_query is not None and user_query != "":
|
107 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
108 |
|
|
|
42 |
Based on the table schema below, question, sql query, and sql response, write a natural language response:
|
43 |
{schema}
|
44 |
|
45 |
+
Conversation History: {chat_history}
|
46 |
Question: {question}
|
47 |
SQL Query: {query}
|
48 |
SQL Response: {response}"""
|
|
|
65 |
)
|
66 |
|
67 |
return chain.stream({
|
68 |
+
"question": user_query,
|
69 |
+
"chat_history": chat_history,
|
70 |
})
|
71 |
|
72 |
load_dotenv()
|
|
|
75 |
|
76 |
if 'chat_history' not in st.session_state:
|
77 |
st.session_state.chat_history = [
|
78 |
+
AIMessage(content="Hello! I'm a chatbot that can help you with your SQL queries. Ask me anything about your database!")
|
79 |
]
|
80 |
|
81 |
if 'db' not in st.session_state:
|
|
|
105 |
|
106 |
user_query = st.chat_input("Type a message...")
|
107 |
|
108 |
+
# conversation
|
109 |
+
for message in st.session_state.chat_history:
|
110 |
+
if isinstance(message, AIMessage):
|
111 |
+
with st.chat_message("AI"):
|
112 |
+
st.write(message.content)
|
113 |
+
elif isinstance(message, HumanMessage):
|
114 |
+
with st.chat_message("Human"):
|
115 |
+
st.write(message.content)
|
116 |
+
|
117 |
+
|
118 |
if user_query is not None and user_query != "":
|
119 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
120 |
|