Image 类用于创建和处理要在聊天机器人用户界面中发送和显示的图像元素。

您必须提供 URL、路径或内容字节之一。

属性

name
str

要在用户界面中显示的图像名称。

display
ElementDisplay

确定图像元素在用户界面中的显示方式。选项包括:“侧边”、“内联”或“页面”。

size
ElementSize

确定图像的大小。仅在 display=“inline” 时有效。选项包括:“小”、“中”(默认)或“大”。

url
str

图像源的远程 URL。

path
str

图像的本地文件路径。

content
bytes

图像的文件内容(字节格式)。

示例

import chainlit as cl


@cl.on_chat_start
async def start():
    image = cl.Image(path="./cat.jpeg", name="image1", display="inline")

    # Attach the image to the message
    await cl.Message(
        content="This message has an image!",
        elements=[image],
    ).send()