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 returning/yielding chat message from callback #5712

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

ahuang11
Copy link
Contributor

Closes #5708

@codecov
Copy link

codecov bot commented Oct 22, 2023

Codecov Report

Merging #5712 (81cc5e5) into main (0067d40) will increase coverage by 1.65%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5712      +/-   ##
==========================================
+ Coverage   82.45%   84.11%   +1.65%     
==========================================
  Files         288      288              
  Lines       41995    42054      +59     
==========================================
+ Hits        34629    35374     +745     
+ Misses       7366     6680     -686     
Flag Coverage Δ
ui-tests 40.74% <15.25%> (+2.62%) ⬆️
unitexamples-tests 73.75% <100.00%> (+0.03%) ⬆️

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

Files Coverage Δ
panel/chat/feed.py 93.04% <100.00%> (+0.59%) ⬆️
panel/tests/chat/test_feed.py 99.80% <100.00%> (+0.02%) ⬆️

... and 19 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Oct 22, 2023

UPDATE: WORKS NOW

I've tested that async and return works.

But async and yield does not seem to work. I see the below error right after uploading a csv file.

import panel as pn
import pandas as pd

agent_user="Pandas Agent"
agent_avatar="🐼"

pn.extension("perspective")

def _create_message(message):
    return pn.chat.ChatMessage(message, user="Pandas Agent", avatar="🐼")

async def callback(contents, user, instance):
    if isinstance(contents, pd.DataFrame):
        instance.active=1
        print("I was here")
        yield _create_message("You uploaded a dataframe. Ask me anything about it")
        

    yield _create_message("That is a great question. I don't know.")

chat_interface = pn.chat.ChatInterface(
    widgets=[pn.widgets.FileInput(name="Upload"), pn.widgets.TextInput(name="Message")],
    renderers=pn.pane.Perspective,
    callback=callback,
    callback_exception="verbose",
)
    
chat_interface.send("I'm your LangChain Pandas Agent!", user="Pandas Agent", avatar="🐼", respond=False)
chat_interface.servable()

image

@MarcSkovMadsen MarcSkovMadsen mentioned this pull request Oct 22, 2023
37 tasks
@ahuang11
Copy link
Contributor Author

Should be fixed now.

@MarcSkovMadsen
Copy link
Collaborator

Should be fixed now.

I can confirm its fixed.Thanks.

@philippjfr philippjfr merged commit aff709b into main Oct 23, 2023
11 of 13 checks passed
@philippjfr philippjfr deleted the fix_return_yield_chat_message branch October 23, 2023 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChatInterface callback cannot return ChatMessage
3 participants