seansullivan commited on
Commit
9bf709f
·
verified ·
1 Parent(s): a5622a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -238,17 +238,27 @@ with st.form("chat_form", clear_on_submit=True):
238
  # --- Generate Assistant Response ---
239
  if st.session_state.chat_history and st.session_state.chat_history[-1][0] == "user":
240
  inputs = {"messages": st.session_state.chat_history}
 
 
241
  response_placeholder = st.empty()
242
  assistant_message = ""
243
 
 
244
  for s in graph.stream(inputs, stream_mode="values"):
 
245
  message = s["messages"][-1]
246
  if isinstance(message, tuple):
247
  role, text = message
248
  else:
249
  text = message.content
 
 
250
  assistant_message += text
251
- response_placeholder.markdown(f"**Assistant:** {assistant_message}")
252
 
 
 
 
 
 
253
  st.session_state.chat_history.append(("assistant", assistant_message))
254
- # No rerun needed here either.
 
238
  # --- Generate Assistant Response ---
239
  if st.session_state.chat_history and st.session_state.chat_history[-1][0] == "user":
240
  inputs = {"messages": st.session_state.chat_history}
241
+
242
+ # Create a container for streaming output
243
  response_placeholder = st.empty()
244
  assistant_message = ""
245
 
246
+ # Stream the agent's response chunk-by-chunk.
247
  for s in graph.stream(inputs, stream_mode="values"):
248
+ # Extract the last message from the messages list.
249
  message = s["messages"][-1]
250
  if isinstance(message, tuple):
251
  role, text = message
252
  else:
253
  text = message.content
254
+
255
+ # Append new text and update the markdown display.
256
  assistant_message += text
 
257
 
258
+ # Update the placeholder with the current assistant message.
259
+ # Using unsafe_allow_html=True ensures that any markdown (or embedded HTML) is rendered.
260
+ response_placeholder.markdown(assistant_message, unsafe_allow_html=True)
261
+
262
+ # Once complete, add the full assistant response to the chat history.
263
  st.session_state.chat_history.append(("assistant", assistant_message))
264
+