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

Issue with Feedback Options Not Appearing for Messages Sent via Action Buttons #1466

Open
Elienvalleau opened this issue Oct 22, 2024 · 1 comment
Labels
bug Something isn't working needs-triage

Comments

@Elienvalleau
Copy link

Describe the bug
When a user sends a message via an action button using cl.action_callback, the assistant's reply does not display the feedback options (like/dislike). However, when a user types a message manually, the feedback options appear as expected. It seems that the context is lost within the callback function, preventing the feedback options from being associated with the assistant's responses triggered by action buttons.

To Reproduce
Steps to reproduce the behavior:

  1. Generate follow-up questions using action buttons in the assistant's message:
actions = []
followup_questions = ["Question 1", "Question 2", "Question 3"]
for fq in followup_questions:
    actions.append(cl.Action(name="action_button", value=fq, label=fq))
await cl.Message(content="Suggestions for further analysis:", actions=actions).send()
  1. Implement the on_action callback to handle the action button clicks:
@cl.action_callback("action_button")
async def on_action(action: cl.Action):
    message = cl.Message(content=action.value.strip(), type="user_message")
    await message.send()

    print(f"Context in on_action: {cl.context.__dict__}")

    await on_message(message)
  1. In the on_message function, process the message and send the assistant's reply:
@cl.on_message
async def on_message(message: cl.Message):
    # Processing logic...

Expected behavior
The assistant's reply to a message sent via an action button should display the feedback options (like/dislike), just as it does when a message is typed manually by the user.

Additional context
When printing the context inside the on_action function, certain context attributes like cl.context.current_step are missing or None:

print(f"Context in on_action : {cl.context.__dict__}")

Output :

{
  'loop': <EventLoop running=True closed=False debug=False>,
  'session': <chainlit.session.WebsocketSession object at 0x...>,
  'active_steps': [],
  'emitter': <chainlit.emitter.ChainlitEmitter object at 0x...>
}

It appears that the context is not fully established within the on_action callback, which might be causing the issue.

Chainlit Version: 1.2.0

Python Version: 3.9.10

Question: How can I properly establish or mimic the context within the on_action callback so that the assistant's replies include the feedback options when messages are sent via action buttons?

Any guidance or suggestions on how to resolve this issue would be greatly appreciated. Thank you!

@dosubot dosubot bot added the bug Something isn't working label Oct 22, 2024
Copy link

dosubot bot commented Oct 22, 2024

Hey @Elienvalleau! I'm Dosu, here to help you with any bugs, questions, or contributions you have in mind. Let's tackle this together!

The issue you're experiencing with feedback options not appearing for messages sent via action buttons is likely due to the context not being fully established within the on_action callback. Here are some steps and considerations to help resolve this:

  1. Ensure Proper Context Initialization: The cl.context object should be properly initialized and populated during the execution of an action callback. This involves ensuring that the session and emitter are correctly set up. You might need to manually set or adjust the context within the on_action callback to mimic the context of a normal message processing flow.

  2. Check Feedback Conditions: Feedback options are typically associated with messages when certain conditions are met, such as the message being of type "assistant_message" and having non-empty output. Ensure that these conditions are satisfied in your on_message function when sending the assistant's reply [1].

  3. Use cl.user_session for State Management: Utilize cl.user_session to manage and maintain the state across different callbacks and actions. This can help ensure that the necessary context and session data are preserved when handling messages triggered by action buttons [2].

  4. Debug Context Attributes: Since certain context attributes like cl.context.current_step are missing or None, you may need to explicitly set these attributes if they are required for feedback options to appear. Investigate how these attributes are set during normal message processing and replicate that setup in your callback.

  5. Review Chainlit Version Changes: Since you're using Chainlit version 1.2.0, check if there have been any changes or updates in the feedback mechanism or context handling in recent versions that might affect your implementation.

By ensuring that the context is fully established and the necessary conditions for feedback are met, you should be able to resolve the issue with feedback options not appearing for messages sent via action buttons.

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 needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant