Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ with st.sidebar:
|
|
53 |
# Add a button to clear the session state
|
54 |
if st.button("Clear Session"):
|
55 |
st.session_state.messages = []
|
56 |
-
st.session_state["
|
57 |
st.experimental_rerun()
|
58 |
|
59 |
|
@@ -69,23 +69,23 @@ for message in st.session_state.messages:
|
|
69 |
|
70 |
|
71 |
# React to user input
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
53 |
# Add a button to clear the session state
|
54 |
if st.button("Clear Session"):
|
55 |
st.session_state.messages = []
|
56 |
+
st.session_state["history"] = [{"role": "system", "content": "You are a helpful assistant."}]
|
57 |
st.experimental_rerun()
|
58 |
|
59 |
|
|
|
69 |
|
70 |
|
71 |
# React to user input
|
72 |
+
if prompt := st.chat_input("π Ask any question or feel free to use the examples provided in the left sidebar."):
|
73 |
+
|
74 |
+
# Display user message in chat message container
|
75 |
+
st.chat_message("user").markdown(prompt)
|
76 |
+
|
77 |
+
# Add user message to chat history
|
78 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
79 |
+
st.session_state["history"].append({"role": "user", "content": prompt})
|
80 |
+
|
81 |
+
# API Call
|
82 |
+
bot = ChatBot(history=st.session_state["history"])
|
83 |
+
response = bot.generate_response(prompt)
|
84 |
+
|
85 |
+
# Display assistant response in chat message container
|
86 |
+
with st.chat_message("assistant"):
|
87 |
+
st.markdown(response)
|
88 |
+
|
89 |
+
# Add assistant response to chat history
|
90 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
91 |
+
st.session_state["history"].append({"role": "assistant", "content": response})
|