How to trigger a callback on favorite action on the ChatInterface

I have a ChatInterface, and I’d like to trigger a callback when the user clicks thumbs up and thumbs down, and make the option disappear after being clicked.

The docs suggest this is possible by modifying individual ChatMessages, but I’m not sure how to do that using the ChatInterface? Implementing the example here doesnt work for me, nothing is printed.

chat_interface = pn.chat.ChatInterface(
    message_params = dict(
       reaction_icons={"like": "thumb-up", "dislike": "thumb-down"},
    ),
    button_properties={"send": {"post_callback": bind_on_send}},
    callback=agentCallback,
    show_send=False,
    show_rerun=False,
    show_undo=False,
    show_clear=False,
    show_button_name=False,
    sizing_mode="stretch_both",
    min_height=200,
    width=475,
    name="Chat",
)

The printing works for me. However, it seems like the reaction_icons cannot be updated.

import panel as pn

def react_on_click(reactions, message):
    print(reactions)
    message.reaction_icons = pn.chat.ChatReactionIcons(options={})

def bind_on_send(instance, event):
    message = instance.objects[-1]
    pn.bind(react_on_click, message.param.reactions, message, watch=True)

ci = pn.chat.ChatInterface(button_properties={"send": {"post_callback": bind_on_send}})
ci.show()

Do you mind filing a GitHub issue?

Ahh printing works for me now, thank you! I submitted a github issue here: Can't update message reaction icons after click · Issue #6804 · holoviz/panel · GitHub

Thanks for the submission; I think it will be fixed in Make ChatMessage reaction_icons reactive by ahuang11 · Pull Request #6807 · holoviz/panel · GitHub

1 Like