Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,15 +61,21 @@ with st.sidebar:
|
|
61 |
if "messages" not in st.session_state:
|
62 |
st.session_state.messages = []
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Display chat messages from history on app rerun
|
66 |
for message in st.session_state.messages:
|
67 |
with st.chat_message(message["role"]):
|
68 |
st.markdown(message["content"])
|
69 |
|
70 |
-
|
71 |
# React to user input
|
72 |
-
|
|
|
|
|
73 |
if prompt := st.chat_input("π Ask any question or feel free to use the examples provided in the left sidebar."):
|
74 |
|
75 |
# Display user message in chat message container
|
@@ -77,11 +83,10 @@ if prompt := st.chat_input("π Ask any question or feel free to use the exampl
|
|
77 |
|
78 |
# Add user message to chat history
|
79 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
80 |
-
st.session_state["history"].append({"role": "user", "content": prompt})
|
81 |
|
82 |
# API Call
|
83 |
bot = ChatBot()
|
84 |
-
bot.history = st.session_state
|
85 |
response = bot.generate_response(prompt)
|
86 |
|
87 |
# Display assistant response in chat message container
|
@@ -90,4 +95,3 @@ if prompt := st.chat_input("π Ask any question or feel free to use the exampl
|
|
90 |
|
91 |
# Add assistant response to chat history
|
92 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
93 |
-
st.session_state["history"].append({"role": "assistant", "content": response})
|
|
|
61 |
if "messages" not in st.session_state:
|
62 |
st.session_state.messages = []
|
63 |
|
64 |
+
# Ensure messages are a list of dictionaries
|
65 |
+
if not isinstance(st.session_state.messages, list):
|
66 |
+
st.session_state.messages = []
|
67 |
+
if not all(isinstance(msg, dict) for msg in st.session_state.messages):
|
68 |
+
st.session_state.messages = []
|
69 |
|
70 |
# Display chat messages from history on app rerun
|
71 |
for message in st.session_state.messages:
|
72 |
with st.chat_message(message["role"]):
|
73 |
st.markdown(message["content"])
|
74 |
|
|
|
75 |
# React to user input
|
76 |
+
if "history" not in st.session_state:
|
77 |
+
st.session_state["history"] = [{"role": "system", "content": "You are a helpful assistant."}]
|
78 |
+
|
79 |
if prompt := st.chat_input("π Ask any question or feel free to use the examples provided in the left sidebar."):
|
80 |
|
81 |
# Display user message in chat message container
|
|
|
83 |
|
84 |
# Add user message to chat history
|
85 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
|
|
86 |
|
87 |
# API Call
|
88 |
bot = ChatBot()
|
89 |
+
bot.history = st.session_state.messages # Update history from messages
|
90 |
response = bot.generate_response(prompt)
|
91 |
|
92 |
# Display assistant response in chat message container
|
|
|
95 |
|
96 |
# Add assistant response to chat history
|
97 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|