Switching to another page is triggering sent event on chatinterface
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)
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, 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)
For pn.widgets.TextAreaInput(), it is working.
If we can fix this behaviour for TextAreaInput, it will be great. It looks more attractive in my use case.
Should be fixed by the new ChatAreaInput in panel 1.4.0