Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -11
src/streamlit_app.py
CHANGED
|
@@ -139,17 +139,27 @@ if "current_chat_id" in st.session_state:
|
|
| 139 |
st.write(user_input)
|
| 140 |
|
| 141 |
with st.chat_message("assistant"):
|
|
|
|
| 142 |
response_placeholder = st.empty()
|
| 143 |
full_response = ""
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
st.write(user_input)
|
| 140 |
|
| 141 |
with st.chat_message("assistant"):
|
| 142 |
+
# ... (inside with st.chat_message("assistant"))
|
| 143 |
response_placeholder = st.empty()
|
| 144 |
full_response = ""
|
| 145 |
|
| 146 |
+
# Use stream_mode='values' for a cleaner loop
|
| 147 |
+
for chunk in workflow.stream(
|
| 148 |
+
{"messages": [HumanMessage(user_input)]}, # System message should already be in state
|
| 149 |
+
config=set_config()):
|
| 150 |
+
# The output of a streaming node is the key of the node itself
|
| 151 |
+
if "llmresponse" in chunk:
|
| 152 |
+
ai_message = chunk["llmresponse"]["messages"][-1]
|
| 153 |
+
full_response += ai_message.content
|
| 154 |
+
response_placeholder.markdown(full_response + "▌") # Add a cursor effect
|
| 155 |
+
|
| 156 |
+
# Handle tool calls if they appear in the stream
|
| 157 |
+
elif "tool_node" in chunk:
|
| 158 |
+
# Since we are streaming, render the tool message right away
|
| 159 |
+
# And clear the response placeholder for the next text chunk
|
| 160 |
+
response_placeholder.empty()
|
| 161 |
+
tool_messages = chunk["tool_node"]["messages"]
|
| 162 |
+
for tool_message in tool_messages:
|
| 163 |
+
render_tool_message(tool_message)
|
| 164 |
+
|
| 165 |
+
response_placeholder.markdown(full_response) # Final update without cursor
|