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

Switching to another page is triggering sent event on chatinterface #6347

Closed
nemesis00sam opened this issue Feb 15, 2024 · 5 comments
Closed
Labels
chat A label for chat usage

Comments

@nemesis00sam
Copy link

nemesis00sam commented Feb 15, 2024

Hi;

I shared a small example with you. I encounter the same problem in all panel apps using chatbot. I also tested this code in panel==1.3.8.

Problem:
I'm writing a prompt in chatbot interface then I'm changing the active window. (I'm going to another window in chrome) When I get back to panel application, message was already sent.

Thanks in advance.

"""
Demonstrates how to use the `ChatInterface` and a `callback` function to stream back
responses.

The chatbot Assistant echoes back the message entered by the User in a *streaming*
fashion.
"""
from time import sleep
import panel as pn
pn.extension(design="material")

def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    sleep(1)
    message = ""
    for char in f"Echoing {user}: {contents}":
        sleep(0.05)
        message += char
        yield message


chat_interface = pn.chat.ChatInterface(callback=callback,placeholder_text="Waiting for reply...",placeholder_threshold=0.1,)
chat_interface.send(
    "Enter a message in the TextInput below and receive an echo!",
    user="System",
    respond=False,
)

pn.serve(chat_interface,port=8004)
@ahuang11
Copy link
Contributor

ahuang11 commented Feb 15, 2024

Thanks for reporting. I believe you can set auto_send_types=[] to prevent it from auto sending. https://panel.holoviz.org/reference/chat/ChatInterface.html#core

Or, use widgets=[pn.widgets.TextAreaInput()] instead.

Note, both of these methods will prevent sending upon pressing your Enter key. It's on the chat roadmap to implement a custom chat input to support hotkeys soon.

@ahuang11 ahuang11 added usage chat A label for chat labels Feb 15, 2024
@nemesis00sam
Copy link
Author

@ahuang11, I tried but behaviour doesn't change.

from time import sleep

import panel as pn

pn.extension(design="material")




def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    sleep(10)
    message = ""
    for char in f"Echoing {user}: {contents}":
        sleep(0.05)
        message += char
        yield message


chat_interface = pn.chat.ChatInterface(callback=callback,
                                       auto_send_types=[],
                                       placeholder_text="Waiting for reply...",
                                       placeholder_threshold=0.1,)
chat_interface.send(
    "Enter a message in the TextInput below and receive an echo!",
    user="System",
    respond=False,
)

pn.serve(chat_interface,port=8004)

@nemesis00sam
Copy link
Author

For pn.widgets.TextAreaInput(), it is working.

@nemesis00sam
Copy link
Author

If we can fix this behaviour for TextAreaInput, it will be great. It looks more attractive in my use case.

@philippjfr
Copy link
Member

Should be fixed by the new ChatAreaInput in panel 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat A label for chat usage
Projects
None yet
Development

No branches or pull requests

3 participants