.*$", "", visible_response, flags=re.DOTALL)
visible_placeholder.markdown(visible_response)
# If there's an in-progress thinking part, display it in a pretty style
if in_progress:
# You can further format in_progress as you like; here we wrap it in a styled div.
thinking_html = f"""
Internal Reasoning (in progress):
{in_progress}
"""
thinking_placeholder.markdown(thinking_html, unsafe_allow_html=True)
else:
thinking_placeholder.empty()
# After streaming completes:
# Extract all completed blocks (the final internal reasoning that was closed)
final_thinking = re.findall(r"(.*?)", full_response, flags=re.DOTALL)
# The final visible response: remove any blocks or any in-progress open block.
final_visible = re.sub(r".*?", "", full_response, flags=re.DOTALL)
final_visible = re.sub(r".*$", "", final_visible, flags=re.DOTALL)
st.session_state.chat_history.append({
"role": "assistant",
"content": final_visible,
"thinking": final_thinking
})
st.session_state.pending_response = False