Skip to content

Commit a30a722

Browse files
committed
feat(contents_shinychat): Add new contents_shinychat() and contents_shinychat_chunk()
These new functions are the singledispatch equivalent of the previous normalize_message() and normalize_message_chunk(). Although not quite as flexible as the previous strategies pattern, it's much simpler (implementation wise and also for those registering new methods) and aligns much better with the vision for the R package
1 parent 82a1f99 commit a30a722

File tree

4 files changed

+217
-311
lines changed

4 files changed

+217
-311
lines changed

pkg-py/src/shinychat/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
from ._chat import Chat, chat_ui
2+
from ._chat_normalize import contents_shinychat, contents_shinychat_chunk
23
from ._markdown_stream import MarkdownStream, output_markdown_stream
34

4-
__all__ = ["Chat", "chat_ui", "MarkdownStream", "output_markdown_stream"]
5+
__all__ = [
6+
"Chat",
7+
"chat_ui",
8+
"MarkdownStream",
9+
"output_markdown_stream",
10+
"contents_shinychat",
11+
"contents_shinychat_chunk",
12+
]

pkg-py/src/shinychat/_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
is_chatlas_chat_client,
5353
set_chatlas_state,
5454
)
55-
from ._chat_normalize import normalize_message, normalize_message_chunk
55+
from ._chat_normalize import contents_shinychat, contents_shinychat_chunk
5656
from ._chat_provider_types import (
5757
AnthropicMessage,
5858
GoogleMessage,
@@ -636,7 +636,7 @@ async def append_message(
636636
self._pending_messages.append((message, False, "append", None))
637637
return
638638

639-
msg = normalize_message(message)
639+
msg = contents_shinychat(message)
640640
msg = await self._transform_message(msg)
641641
if msg is None:
642642
return
@@ -753,7 +753,7 @@ async def _append_message_chunk(
753753
self._current_stream_id = stream_id
754754

755755
# Normalize various message types into a ChatMessage()
756-
msg = normalize_message_chunk(message)
756+
msg = contents_shinychat_chunk(message)
757757

758758
if operation == "replace":
759759
self._current_stream_message = (

0 commit comments

Comments
 (0)