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

Add custom callbacks to ChatInterface buttons #5839

Merged
merged 7 commits into from
Nov 27, 2023
Merged

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Nov 9, 2023

Closes #5711

So users can add additional functionality to existing buttons, or add additional buttons easily.

I can't figure out how to drop event here though.

import panel as pn

pn.extension()

pn.chat.ChatInterface(
    custom_callbacks={
        ("Random", "activity"): lambda instance, event: instance.send(
            "Here have a random number"
        ),
        "send": lambda instance, event: instance.send("Hi another send"),
    }
)
image

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (2867559) 84.16% compared to head (2970c8f) 84.20%.

Files Patch % Lines
panel/chat/interface.py 96.36% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5839      +/-   ##
==========================================
+ Coverage   84.16%   84.20%   +0.04%     
==========================================
  Files         291      291              
  Lines       42807    42907     +100     
==========================================
+ Hits        36027    36130     +103     
+ Misses       6780     6777       -3     
Flag Coverage Δ
ui-tests 40.87% <14.15%> (-0.07%) ⬇️
unitexamples-tests 72.49% <98.23%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11
Copy link
Contributor Author

ahuang11 commented Nov 10, 2023

@MarcSkovMadsen in regards to #5711, with this PR, you can do something like:

def reset_welcome(instance, event):
    instance.send(
        state.welcome_message, user="Pandas Agent", avatar="🐼", respond=False
    )
...
ChatInterface(..., button_properties={"reset": {"post_callback": reset_welcome}})

@ahuang11 ahuang11 marked this pull request as ready for review November 10, 2023 15:09
@ahuang11 ahuang11 changed the title Add custom callbacks Add custom callbacks to ChatInterface buttons Nov 14, 2023
panel/chat/interface.py Outdated Show resolved Hide resolved
panel/chat/interface.py Outdated Show resolved Hide resolved
panel/chat/interface.py Outdated Show resolved Hide resolved
panel/chat/interface.py Outdated Show resolved Hide resolved
panel/chat/interface.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member

Needs rebasing after the merge of the serialize PR also typing_extensions is no longer a dependency so the Self import has to be removed.

@philippjfr philippjfr merged commit 41d6b4f into main Nov 27, 2023
13 checks passed
@philippjfr philippjfr deleted the add_custom_callbacks branch November 27, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChatInterface: Expose Actions
2 participants