Chat elements

Streamlit provides a few commands to help you build conversational apps. These chat elements are designed to be used in conjunction with each other, but you can also use them separately.

st.chat_message lets you insert a chat message container into the app so you can display messages from the user or the app. Chat containers can contain other Streamlit elements, including charts, tables, text, and more. st.chat_input lets you display a chat input widget so the user can type in a message. Remeber to check out st.status to display output from long-running processes and external API calls.


Chat message

Insert a chat message container.

import numpy as np
with st.chat_message("user"):
    st.write("Hello đź‘‹")
    st.line_chart(np.random.randn(30, 3))

Chat input

Display a chat input widget.

prompt = st.chat_input("Say something")
if prompt:
    st.write(f"The user has sent: {prompt}")

Status container

Display output of long-running tasks in a container.

with st.status('Running'):

Still have questions?

Our forums are full of helpful information and Streamlit experts.

Was this page helpful?

editEdit this page on GitHub