Anyone has formatting issues like this in the chat message with streaming?

Using latest version of streamlit

This is the code:


    with st.chat_message("assistant"):
        stream = client.chat.completions.create(
            model=st.session_state['open-ai-model'],
            messages=messages,
            stream=True,
        )
        response = st.write_stream(stream)

Formatting issue:

Hi @Odrec

This appears to be a when the output contains special formats. Instead of st.write_stream, could you try replacing that with st.markdown. The down side is that the typewriter effect would not be used.

Hope this helps

Hi, thanks for the answer.

I tried it like this but now I get random white spaces between words and every partial response is in a new line


    with st.chat_message("assistant"):
        stream = client.chat.completions.create(
            model=st.session_state['open-ai-model'],
            messages=messages,
            stream=True,
        )
        response = []
        partial_response = []
        for chunk in stream:
            delta = chunk.choices[0].delta
            if delta:
                if len(partial_response) < 50:
                    chunk_content = chunk.choices[0].delta.content
                    partial_response.append(chunk_content)
                else:
                    st.markdown(' '.join(partial_response))
                    response.extend(partial_response)
                    partial_response = []
        response = ' '.join(response)