Tip
Read the Build a basic LLM chat app tutorial to learn how to use st.chat_message and st.chat_input to build chat-based apps.
st.chat_message
Insert a chat message container.
To add elements to the returned container, you can use with notation (preferred) or just call methods directly on the returned object. See the examples below.
| Function signature[source] | |
|---|---|
st.chat_message(name, *, avatar=None) | |
| Parameters | |
name ("user", "assistant", "ai", "human", or str) | The name of the message author. Can be "human"/"user" or "ai"/"assistant" to enable preset styling and avatars. Currently, the name is not shown in the UI but is only set as an accessibility label. For accessibility reasons, you should not use an empty string. |
avatar (str, numpy.ndarray, or BytesIO) | The avatar shown next to the message. Can be one of:
If None (default), uses default icons if name is "user", "assistant", "ai", "human" or the first letter of the name value. |
| Returns | |
(Container) | A single container that can hold multiple elements. |
Examples
You can use with notation to insert any element into an expander
PythonOr you can just call methods directly in the returned objects:
Python
For an overview of the st.chat_message and st.chat_input API, check out this video tutorial by Chanin Nantasenamat (@dataprofessor), a Senior Developer Advocate at Streamlit.
Still have questions?
Our forums are full of helpful information and Streamlit experts.
