The Message
class is designed to send, stream, update or remove messages.
Parameters
The content of the message.
The author of the message, defaults to the chatbot name defined in your config
file.
Elements to attach to the message.
Actions to attach to the message.
Send a message
Send a new message to the UI.
import chainlit as cl
@cl.on_message
async def main(message: cl.Message):
await cl.Message(
content=f"Received: {message.content}",
).send()
Stream a message
Send a message token by token to the UI.
import chainlit as cl
token_list = ["the", "quick", "brown", "fox"]
@cl.on_chat_start
async def main():
msg = await cl.Message(content="").send()
for token in token_list:
await msg.stream_token(token)
await msg.update()
Update a message
Update a message that already has been sent.
import chainlit as cl
@cl.on_chat_start
async def main():
msg = cl.Message(content="Hello!")
await msg.send()
await cl.sleep(2)
msg.content = "Hello again!"
await msg.update()
Remove a message
Remove a message from the UI.
import chainlit as cl
@cl.on_chat_start
async def main():
msg = cl.Message(content="Message 1")
await msg.send()
await cl.sleep(2)
await msg.remove()