Streaming chat response -> chat history

I have a streaming response object from an LLM.

I write it in a streaming manner with
st.chat_message(ā€œassistantā€).write(response)
Thatā€™s great.

Now I want to append the message that I wrote to the chat history:
st.session_state.messages.append({ā€œroleā€: ā€œassistantā€, ā€œcontentā€: msg})

But how do I get the msg from the response object after it has been written?

I do not succeed in doing thisā€¦

1 Like

I figured it out:

with st.chat_message(ā€œassistantā€):
msg = st.write_stream(response)

2 Likes