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 placeholder while loading to ChatFeed #7042

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions panel/chat/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ def _update_placeholder(self):
**self.placeholder_params
)

@param.depends("loading", watch=True, on_init=True)
Copy link
Member

Choose a reason for hiding this comment

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

How does this interact with the usual loading spinner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean something like pn.Column("Hello", loading=True)?

image

I don't think anything gets overlaid on ChatInterface besides the individual buttons
pn.chat.ChatInterface("Hello", loading=True).show()

image

def _show_placeholder(self):
if self.loading:
self.append(self._placeholder)
else:
self._replace_placeholder(None)

def _replace_placeholder(self, message: ChatMessage | None = None) -> None:
"""
Replace the placeholder from the chat log with the message
Expand All @@ -348,6 +355,8 @@ def _replace_placeholder(self, message: ChatMessage | None = None) -> None:
self.append(message)

try:
if self.loading:
return
self.remove(self._placeholder)
except ValueError:
pass
Expand Down
17 changes: 17 additions & 0 deletions panel/tests/chat/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def test_init_with_help_text(self):
assert message.object == "Instructions"
assert message.user == "Help"

def test_init_with_loading(self):
chat_feed = ChatFeed(loading=True)
assert chat_feed._placeholder in chat_feed._chat_log
chat_feed.loading = False
assert chat_feed._placeholder not in chat_feed._chat_log

def test_update_header(self):
chat_feed = ChatFeed(header="1")
assert chat_feed._card.header == "1"
Expand Down Expand Up @@ -1136,6 +1142,17 @@ def callback(cls, contents, user):
wait_until(lambda: len(chat_feed.objects) == 2)
assert chat_feed.objects[1].object == "User: Message"

def test_persist_placeholder_while_loading(self, chat_feed):
def callback(contents):
assert chat_feed._placeholder in chat_feed._chat_log
return "hey testing"

chat_feed.loading = True
chat_feed.callback = callback
chat_feed.send("Message", respond=True)
assert chat_feed._placeholder in chat_feed._chat_log


@pytest.mark.xdist_group("chat")
class TestChatFeedSerializeForTransformers:

Expand Down
Loading