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

Minor cleanup of chat components #7751

Merged
merged 3 commits into from
Mar 2, 2025
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
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
Loading