Action 类旨在创建和管理要发送并在聊天机器人用户界面中显示的操作。操作由用户可以交互的按钮组成,这些交互会触发应用程序中的特定功能。

属性

名称
str

操作的名称,应与操作回调匹配。

负载
Dict

与操作相关的负载。

图标
str

操作按钮的 lucide 图标名称。参见 https://lucide.dev/icons/

标签
str

操作的标签。这是用户将看到的内容。如果未提供标签或图标,则将显示名称作为备用。

工具提示
str

操作的描述。这是用户将鼠标悬停在操作上时看到的内容。

用法

import chainlit as cl

@cl.action_callback("action_button")
async def on_action(action):
    await cl.Message(content=f"Executed {action.name}").send()
    # Optionally remove the action button from the chatbot user interface
    await action.remove()

@cl.on_chat_start
async def start():
    # Sending an action button within a chatbot message
    actions = [
        cl.Action(name="action_button", payload={"value": "example_value"}, label="Click me!")
    ]

    await cl.Message(content="Interact with this action button:", actions=actions).send()