Display streaming response that may have Latex

I am using streaming with streamlit as below

                for response in client.chat.completions.create(
                    model=st.session_state["openai_model"],
                    messages=messages_so_far,
                    stream=True,
                ):
                    full_response += (response.choices[0].delta.content or "")
                    message_placeholder.markdown(full_response + "β–Œ")

The issue is my response may contain math equations which are likely to be latex. How do I show the display as equations ? Right now, it shows as

[ \rho \left( \frac{\partial \mathbf{u}}{\partial t} + \mathbf{u} \cdot \nabla \mathbf{u} \right) = -\nabla p + \mu \nabla^2 \mathbf{u} + \mathbf{f} ]
1 Like

Hi @kris_k

Can you encapsulate the output to be displayed using st.latex()

More info in the Docs:

Did you manage to solve this? My idea so far is to create a function that checks the chunks as it streams to determine if its LaTeX or not and format it but im open to a simpler solution if there is one

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.