Skip to content

Commit

Permalink
Minor cleanup of chat components (#7751)
Browse files Browse the repository at this point in the history
* Wrap default status badges in functions

* Allow overriding step_type

* Drop unneccesary batch_call_watcher
  • Loading branch information
philippjfr authored Mar 2, 2025
1 parent 358df11 commit 5d3ab46
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion panel/chat/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ class ChatFeed(ListPanel):

_card_type: ClassVar[type[Card]] = Card
_message_type: ClassVar[type[ChatMessage]] = ChatMessage
_step_type: ClassVar[type[ChatStep]] = ChatStep

_stylesheets: ClassVar[list[str]] = [f"{CDN_DIST}css/chat_feed.css"]

def __init__(self, *objects, **params):
Expand Down Expand Up @@ -836,7 +838,7 @@ def add_step(
]
if "context_exception" not in step_params:
step_params["context_exception"] = self.callback_exception
step = ChatStep(**step_params)
step = self._step_type(**step_params)

step._instance = self

Expand Down
10 changes: 4 additions & 6 deletions panel/chat/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,11 @@ def _serialize_for_transformers(
async def _update_input_disabled(self):
busy_states = (CallbackState.RUNNING, CallbackState.GENERATING)
if not self.show_stop or self._callback_state not in busy_states or self._callback_future is None:
with param.parameterized.batch_call_watchers(self):
self._buttons["send"].visible = True
self._buttons["stop"].visible = False
self._buttons["send"].visible = True
self._buttons["stop"].visible = False
else:
with param.parameterized.batch_call_watchers(self):
self._buttons["send"].visible = False
self._buttons["stop"].visible = True
self._buttons["send"].visible = False
self._buttons["stop"].visible = True

async def _cleanup_response(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions panel/chat/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
)

DEFAULT_STATUS_BADGES = {
"pending": BooleanStatus(value=False, margin=0, color="primary"),
"running": BooleanStatus(value=True, margin=0, color="warning"),
"success": BooleanStatus(value=True, margin=0, color="success"),
"failed": BooleanStatus(value=True, margin=0, color="danger"),
"pending": lambda: BooleanStatus(value=False, margin=0, color="primary"),
"running": lambda: BooleanStatus(value=True, margin=0, color="warning"),
"success": lambda: BooleanStatus(value=True, margin=0, color="success"),
"failed": lambda: BooleanStatus(value=True, margin=0, color="danger"),
}


Expand Down
3 changes: 3 additions & 0 deletions panel/chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import Iterable
from io import BytesIO
from textwrap import indent
from types import FunctionType
from typing import Any, Union

import param
Expand Down Expand Up @@ -48,6 +49,8 @@ def avatar_lookup(

# now lookup the avatar
avatar = updated_avatars.get(alpha_numeric_key, avatar)
if isinstance(avatar, FunctionType):
avatar = avatar()
if isinstance(avatar, str):
avatar = avatar.format(dist_path=CDN_DIST)
return avatar
Expand Down

0 comments on commit 5d3ab46

Please sign in to comment.