ChatInput
The ChatInput widget provides a simple text input field with a send button, designed for
chat-style Mercury Apps. It is typically used together with Chat and
Message to build conversational interfaces.
By default, ChatInput is displayed at the bottom of the main view.
Basic Usage
Section titled “Basic Usage”Create a chat input and read the submitted message:
import mercury as mr
# ChatInput is displayed at the bottom of the main view by defaultprompt = mr.ChatInput()
if prompt.value: # do something with user prompt print("User said:", prompt.value)How Submission Works ⭐
Section titled “How Submission Works ⭐”prompt.value contains the last submitted message.
A typical Mercury App flow looks like this:
- User types a message and clicks the send button (or presses Enter).
prompt.valueis set to the submitted text.- Your notebook code runs and reads
prompt.value. - After the notebook finishes executing, Mercury resets
prompt.valueback to""so the next run starts clean.
Example: Chat + ChatInput
Section titled “Example: Chat + ChatInput”A minimal chat loop:
import mercury as mr
chat = mr.Chat()prompt = mr.ChatInput()
if prompt.value: # user message chat.add(mr.Message(markdown=prompt.value, role="user", emoji="👤"))
# assistant response chat.add(mr.Message(markdown="Got it ✅", role="assistant", emoji="🤖"))Layout
Section titled “Layout”Use the position argument to control where the widget is rendered:
"sidebar"— in the sidebar"inline"— directly in the notebook output flow"bottom"— at the bottom of the main view (default)
prompt = mr.ChatInput(position="inline")ChatInput Props
Section titled “ChatInput Props”type: string
The last submitted message.
- Updated only when the user submits
- Reset to
""after all cells are executed
placeholder
Section titled “placeholder”type: string
Placeholder text shown inside the input.
Default: "Type a message..."
button_icon
Section titled “button_icon”type: string
Text (or emoji) displayed on the send button.
Default: "➤"
send_on_enter
Section titled “send_on_enter”type: bool
If True, pressing Enter submits the message.
Default: True
position
Section titled “position”type: "sidebar" | "inline" | "bottom"
Controls where the widget is rendered.
Default: "bottom"
custom_css
Section titled “custom_css”type: string
Additional CSS appended to the widget’s default styles.
type: string
Unique identifier to distinguish widgets with identical arguments.
ChatInputis designed for short, single-line messages.- The widget clears the visible input field immediately after submission.
valueis best treated as “consume once during the current run”.