From a6dd061246f2f7df43f25dbed788cac09ad39778 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 24 Jul 2024 16:09:30 +0200 Subject: [PATCH] Improvements for ChatInterface (#7009) * Ensure you can pass message_params to ChatInterface.stream * Allow providing existing steps_column to ChatFeed.add_step --- panel/chat/feed.py | 5 ++++- panel/chat/interface.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/panel/chat/feed.py b/panel/chat/feed.py index 58c47fb923..77afdf990e 100644 --- a/panel/chat/feed.py +++ b/panel/chat/feed.py @@ -705,6 +705,7 @@ def add_step( append: bool = True, user: str | None = None, avatar: str | bytes | BytesIO | None = None, + steps_column: Column | None = None, **step_params ) -> ChatStep: """ @@ -723,6 +724,9 @@ def add_step( avatar : str | bytes | BytesIO | None The avatar to use; overrides the message's avatar if provided. Will default to the avatar parameter. Only applicable if steps is "new". + steps_column : Column | None + An existing Column of steps to stream to, if None is provided + it will default to the last Column of steps or create a new one. step_params : dict Parameters to pass to the ChatStep. """ @@ -740,7 +744,6 @@ def add_step( for obj in step ] step = ChatStep(**step_params) - steps_column = None if append: last = self._chat_log[-1] if self._chat_log else None if last is not None and isinstance(last.object, Column) and ( diff --git a/panel/chat/interface.py b/panel/chat/interface.py index 57e9614ff7..9c8df18e61 100644 --- a/panel/chat/interface.py +++ b/panel/chat/interface.py @@ -681,6 +681,7 @@ def stream( avatar: str | bytes | BytesIO | None = None, message: ChatMessage | None = None, replace: bool = False, + **message_params ) -> ChatMessage | None: """ Streams a token and updates the provided message, if provided. @@ -715,4 +716,4 @@ def stream( # so only set to the default when not a ChatMessage user = user or self.user avatar = avatar or self.avatar - return super().stream(value, user=user, avatar=avatar, message=message, replace=replace) + return super().stream(value, user=user, avatar=avatar, message=message, replace=replace, **message_params)