Spaces:
Sleeping
Sleeping
File size: 1,871 Bytes
746d2f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
---
title: Chat elements
slug: /develop/api-reference/chat
---
# 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. Remember to check out `st.status` to display output from long-running processes and external API calls.
<TileContainer>
<RefCard href="/develop/api-reference/chat/st.chat_input">
<Image pure alt="screenshot" src="/images/api/chat_input.jpg" />
<h4>Chat input</h4>
Display a chat input widget.
```python
prompt = st.chat_input("Say something")
if prompt:
st.write(f"The user has sent: {prompt}")
```
</RefCard>
<RefCard href="/develop/api-reference/chat/st.chat_message">
<Image pure alt="screenshot" src="/images/api/chat_message.jpg" />
<h4>Chat message</h4>
Insert a chat message container.
```python
import numpy as np
with st.chat_message("user"):
st.write("Hello π")
st.line_chart(np.random.randn(30, 3))
```
</RefCard>
<RefCard href="/develop/api-reference/status/st.status">
<Image pure alt="screenshot" src="/images/api/status.jpg" />
<h4>Status container</h4>
Display output of long-running tasks in a container.
```python
with st.status('Running'):
do_something_slow()
```
</RefCard>
<RefCard href="/develop/api-reference/write-magic/st.write_stream">
<h4>st.write_stream</h4>
Write generators or streams to the app with a typewriter effect.
```python
st.write_stream(my_generator)
st.write_stream(my_llm_stream)
```
</RefCard>
</TileContainer>
|