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

Fix post callback for default #5998

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Dec 6, 2023

Fixes post callback for existing buttons.

Also, attaches callback/post_callback to auto send on value change.

import panel as pn
pn.extension()

def pre_callback(instance, event):
    instance.send("This sends before send", respond=False)

def post_callback(instance, event):
    instance.send("This sends after send", respond=False)

chat_interface = pn.chat.ChatInterface(button_properties = {
    "send": {"post_callback": post_callback, "callback": pre_callback},
})
chat_interface.show()
Screen.Recording.2023-12-05.at.4.48.38.PM.mov

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

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

Comparison is base (808bfc1) 83.10% compared to head (a34e366) 22.62%.

Files Patch % Lines
panel/tests/chat/test_interface.py 14.28% 18 Missing ⚠️
panel/chat/interface.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5998       +/-   ##
===========================================
- Coverage   83.10%   22.62%   -60.48%     
===========================================
  Files         291      291               
  Lines       43522    43546       +24     
===========================================
- Hits        36170     9854    -26316     
- Misses       7352    33692    +26340     
Flag Coverage Δ
ui-tests ?
unitexamples-tests 22.62% <12.00%> (-50.14%) ⬇️

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.

):
"""
Wrap the callback and post callback around the default callback.
"""
def decorate(default_callback: Callable):
def wrapper(self, event: param.parameterized.Event):
if name == "send" and not self.active_widget.value:
# don't trigger if no message to prevent duplication
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is primarily because value gets reset to "", and re-triggers the callback without this clause

@philippjfr philippjfr merged commit 3b63946 into main Dec 6, 2023
12 of 13 checks passed
@philippjfr philippjfr deleted the fix_post_callback_with_default_callback branch December 6, 2023 10:11
clear_button = chat_interface._input_layout[-1]
chat_interface.send("This shouldn't show up!", respond=False)
clear_button.param.trigger("clicks")
time.sleep(0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have reviewed this more closely, time.sleep should not be used in the test suite (except for very rare cases). Use the wait_until utility.

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.

2 participants