Skip to content

Commit

Permalink
Improvements for ChatInterface (#7009)
Browse files Browse the repository at this point in the history
* Ensure you can pass message_params to ChatInterface.stream

* Allow providing existing steps_column to ChatFeed.add_step
  • Loading branch information
philippjfr authored Jul 24, 2024
1 parent 84801d0 commit a6dd061
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion panel/chat/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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.
"""
Expand All @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion panel/chat/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

0 comments on commit a6dd061

Please sign in to comment.