mo.ui.chat
Create an AI-powered chat interface with conversation history.
Signature
mo.ui.chat(
model: Callable[[list[ChatMessage], ChatModelConfig], object],
*,
prompts: list[str] | None = None,
on_message: Callable[[list[ChatMessage]], None] | None = None,
show_configuration_controls: bool = False,
config: ChatModelConfigDict | None = None,
allow_attachments: bool | list[str] = False,
max_height: int | None = None,
disabled: bool = False
)
Parameters
Function that takes messages and config, returns response
Suggested prompts displayed to user
Callback when new message is sent
show_configuration_controls
Show temperature/tokens controls
Default model configuration
allow_attachments
bool | list[str]
default:"False"
Allow file attachments (True for all types, or list of extensions)
Examples
import marimo as mo
from pydantic_ai import Agent
# Create agent
agent = Agent("openai:gpt-4")
# Create chat interface
chat = mo.ui.chat(
agent,
prompts=[
"Explain quantum computing",
"Write a Python function",
]
)
chat
# Custom model function
def my_model(messages, config):
# Process messages and return response
last_message = messages[-1].content
return f"You said: {last_message}"
chat = mo.ui.chat(
my_model,
show_configuration_controls=True
)
# With attachments
chat = mo.ui.chat(
agent,
allow_attachments=[".pdf", ".txt", ".md"]
)
ChatMessage Structure
Messages have:
role: “user” or “assistant”
content: Message text
attachments: List of attached files
timestamp: When message was sent
Use chat.value to access the full conversation history.