star

Tip

Read the Build conversational apps tutorial to learn how to use st.chat_message and st.chat_input to build chat-based apps.

Display a chat input widget.

Warning

Chat input can only be used once per app page and inside the main area of the app. It cannot be used in the sidebar, columns, expanders, forms or tabs. We plan to support this in the future.

Function signature[source]

st.chat_input(placeholder="Your message", *, key=None, max_chars=None, disabled=False, on_submit=None, args=None, kwargs=None)

Parameters

placeholder (str)

A placeholder text shown when the chat input is empty. Defaults to "Your message". For accessibility reasons, you should not use an empty string.

key (str or int)

An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

max_chars (int or None)

The maximum number of characters that can be entered. If None (default), there will be no maximum.

disabled (bool)

Whether the chat input should be disabled. Defaults to False.

on_submit (callable)

An optional callback invoked when the chat input's value is submitted.

args (tuple)

An optional tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

Returns

(str or None)

The current (non-empty) value of the text input widget on the last run of the app, None otherwise.

Examples

import streamlit as st

prompt = st.chat_input("Say something")
if prompt:
    st.write(f"User has sent the following prompt: {prompt}")

For an overview of the st.chat_input and st.chat_message API, check out this video tutorial by Chanin Nantasenamat (@dataprofessor), a Senior Developer Advocate at Streamlit.

forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.

Was this page helpful?

editEdit this page on GitHub