The Text class allows you to display a text element in the chatbot UI. This class takes a string and creates a text element that can be sent to the UI. It supports the markdown syntax for formatting text. You must provide either an url or a path or content bytes.

Attributes

name
str
The name of the text element to be displayed in the UI.
content
Union[str, bytes]
The text string or bytes that should be displayed as the content of the text element.
url
str
The remote URL of the text source.
path
str
The local file path of the text file.
display
ElementDisplay
Determines how the text element should be displayed in the UI. Choices are “side”, “inline”, or “page”.
language
str
Language of the code if the text is a piece of code. See https://react-code-blocks-rajinwonderland.vercel.app/?path=/story/codeblock—supported-languages for a list of supported languages.

Example

import chainlit as cl


@cl.on_chat_start
async def start():
    text_content = "Hello, this is a text element."
    elements = [
        cl.Text(name="simple_text", content=text_content, display="inline")
    ]

    await cl.Message(
        content="Check out this text element!",
        elements=elements,
    ).send()