Skip to content

Commit c9fad38

Browse files
committed
Drop .clear() method in favor of replace
1 parent 35837bc commit c9fad38

File tree

2 files changed

+12
-11
lines changed
  • shiny/ui
  • tests/playwright/shiny/components/chat/append_message_context

2 files changed

+12
-11
lines changed

shiny/ui/_chat.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,12 +1499,17 @@ def __init__(self, chat: Chat, stream_id: str):
14991499
self._chat = chat
15001500
self._stream_id = stream_id
15011501

1502-
async def clear(self):
1502+
async def replace(self, message_chunk: Any):
15031503
"""
1504-
Set the stream back to its original state.
1504+
Replace the content of the stream with new content.
1505+
1506+
Parameters
1507+
-----------
1508+
message_chunk
1509+
The new content to replace the current content.
15051510
"""
15061511
await self._chat._append_message_chunk(
1507-
"",
1512+
message_chunk,
15081513
operation="replace",
15091514
stream_id=self._stream_id,
15101515
)

tests/playwright/shiny/components/chat/append_message_context/app.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ async def _():
4848
await asyncio.sleep(SLEEP_TIME)
4949
await msg.append(" stream")
5050
await asyncio.sleep(SLEEP_TIME)
51-
await msg.clear()
52-
await asyncio.sleep(SLEEP_TIME)
53-
await msg.append("Finished")
51+
await msg.replace("Finished")
5452

5553

5654
@reactive.effect
@@ -76,8 +74,7 @@ async def _():
7674
async with chat.message_stream_context() as inner:
7775
await inner.append("Inner start")
7876
await asyncio.sleep(SLEEP_TIME)
79-
await inner.clear()
80-
await inner.append("Inner end")
77+
await inner.replace("Inner end")
8178
await asyncio.sleep(SLEEP_TIME)
8279
await outer.append("Outer end")
8380

@@ -88,7 +85,7 @@ async def _():
8885
async with chat.message_stream_context() as outer:
8986
await outer.append("Outer start")
9087
await asyncio.sleep(SLEEP_TIME)
91-
await outer.clear()
88+
await outer.replace("")
9289
async with chat.message_stream_context() as inner:
9390
await inner.append("Inner start")
9491
await asyncio.sleep(SLEEP_TIME)
@@ -116,5 +113,4 @@ async def inner_stream():
116113
await stream.append("Inner start")
117114
await asyncio.sleep(SLEEP_TIME)
118115
await stream.append("Inner progress")
119-
await stream.clear()
120-
await stream.append("Inner end")
116+
await stream.replace("Inner end")

0 commit comments

Comments
 (0)