Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action buttons not persisting #1489

Open
Elienvalleau opened this issue Oct 29, 2024 · 1 comment
Open

Action buttons not persisting #1489

Elienvalleau opened this issue Oct 29, 2024 · 1 comment
Labels
bug Something isn't working data layer Pertains to data layers. needs-triage

Comments

@Elienvalleau
Copy link

Describe the bug
Action buttons (cl.Action) included in the assistant's message are not being persisted in the data storage. This causes issues when attempting to retrieve or reference these action messages later on.

To Reproduce
Steps to reproduce the behavior:

  1. Implement a function that sends a message containing action buttons. For example:
import chainlit as cl

@cl.step(name="Handle New Question", show_input=False)
async def handle_new_question():
    # Generate assistant's response
    response = "Here is the response to your question."

    # Create action buttons
    actions = [
        cl.Action(name="action_button", value="Option 1", label="Option 1"),
        cl.Action(name="action_button", value="Option 2", label="Option 2"),
        cl.Action(name="action_button", value="Option 3", label="Option 3"),
    ]

    # Send the assistant's message with action buttons
    assistant_message = await cl.Message(
        content=response,
        actions=actions,
        type="assistant_message",
        author="assistant"
    ).send()

    # Attempt to store the message using its ID
    message_store[assistant_message.id] = {
        'response': response,
        'actions': [action.value for action in actions]
    }
  1. Run the application and trigger the handle_new_question function by sending a user message.

Expected behavior
All messages sent by the assistant, including those containing action buttons (cl.Action), should be properly stored, so they can be persisted and referenced later.

Question:
How can I ensure that messages containing action buttons are properly persisted in the data storage when using Chainlit?
Is there a recommended way to capture and store these messages so they can be referenced later?
Any guidance or suggestions on how to resolve this issue would be greatly appreciated. Thank you!

@dosubot dosubot bot added bug Something isn't working data layer Pertains to data layers. labels Oct 29, 2024
Copy link

dosubot bot commented Oct 29, 2024

I found a similar issue that was discussed previously. The solution involves using the Message class and its methods to ensure that messages containing action buttons (cl.Action) are properly persisted in the data storage. Here's a brief overview of how you can achieve this:

  1. Create a Message with Actions: Instantiate a Message object with the desired content and actions.

  2. Send the Message: Use the send method of the Message class to send the message to the UI and persist it. This method will also handle sending the associated actions.

  3. Persistence: The send method internally calls _create, which attempts to persist the message using the data layer if it is configured. If a project ID is configured, the messages will be uploaded to the cloud storage.

Here's an example code snippet:

import chainlit as cl

# Define your actions
actions = [
    cl.Action(name="action1", value="action1", label="Action 1"),
    cl.Action(name="action2", value="action2", label="Action 2")
]

# Create a message with actions
message = cl.Message(
    content="This is a message with actions.",
    actions=actions
)

# Send the message and persist it
await message.send()

This approach ensures that the message and its associated actions are sent to the UI and persisted in the data storage, provided that the data layer is properly configured [1][2].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data layer Pertains to data layers. needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant