Skip to content

Commit 7ac2ba1

Browse files
committed
Rename append_message_context() -> message_stream_context()
1 parent 3c0ca35 commit 7ac2ba1

File tree

2 files changed

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

2 files changed

+14
-14
lines changed

shiny/ui/_chat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ async def append_message(
591591
)
592592

593593
@asynccontextmanager
594-
async def append_message_context(self):
594+
async def message_stream_context(self):
595595
"""
596596
Message stream context manager.
597597
@@ -629,9 +629,9 @@ async def append_message_context(self):
629629
630630
@reactive.effect
631631
async def _():
632-
async with chat.append_message_context() as msg:
632+
async with chat.message_stream_context() as msg:
633633
await msg.append("Starting stream...\n\nProgress:")
634-
async with chat.append_message_context() as progress:
634+
async with chat.message_stream_context() as progress:
635635
for x in [0, 50, 100]:
636636
await progress.append(f" {x}%")
637637
await asyncio.sleep(1)
@@ -643,7 +643,7 @@ async def _():
643643
Note
644644
----
645645
A useful pattern for displaying tool calls in a chatbot is for the tool to
646-
display using `.append_message_context()` while the the response generation is
646+
display using `.message_stream_context()` while the the response generation is
647647
happening through `.append_message_stream()`. This allows the tool to display
648648
things like progress updates (or other "ephemeral" content) and optionally
649649
`.restore()` the stream back to it's initial state when ready to display the
@@ -1492,7 +1492,7 @@ def chat_ui(
14921492

14931493
class MessageStream:
14941494
"""
1495-
An object to yield from a `.append_message_context()` context manager.
1495+
An object to yield from a `.message_stream_context()` context manager.
14961496
"""
14971497

14981498
def __init__(self, chat: Chat, stream_id: str):

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def _(user_input: str):
3434
@reactive.effect
3535
@reactive.event(input.stream_1)
3636
async def _():
37-
async with chat.append_message_context() as msg:
37+
async with chat.message_stream_context() as msg:
3838
await msg.append("Basic")
3939
await asyncio.sleep(SLEEP_TIME)
4040
await msg.append(" stream")
@@ -43,7 +43,7 @@ async def _():
4343
@reactive.effect
4444
@reactive.event(input.stream_2)
4545
async def _():
46-
async with chat.append_message_context() as msg:
46+
async with chat.message_stream_context() as msg:
4747
await msg.append("Basic")
4848
await asyncio.sleep(SLEEP_TIME)
4949
await msg.append(" stream")
@@ -56,10 +56,10 @@ async def _():
5656
@reactive.effect
5757
@reactive.event(input.stream_3)
5858
async def _():
59-
async with chat.append_message_context() as outer:
59+
async with chat.message_stream_context() as outer:
6060
await outer.append("Outer start")
6161
await asyncio.sleep(SLEEP_TIME)
62-
async with chat.append_message_context() as inner:
62+
async with chat.message_stream_context() as inner:
6363
await inner.append("Inner start")
6464
await asyncio.sleep(SLEEP_TIME)
6565
await inner.append("Inner end")
@@ -70,10 +70,10 @@ async def _():
7070
@reactive.effect
7171
@reactive.event(input.stream_4)
7272
async def _():
73-
async with chat.append_message_context() as outer:
73+
async with chat.message_stream_context() as outer:
7474
await outer.append("Outer start")
7575
await asyncio.sleep(SLEEP_TIME)
76-
async with chat.append_message_context() as inner:
76+
async with chat.message_stream_context() as inner:
7777
await inner.append("Inner start")
7878
await asyncio.sleep(SLEEP_TIME)
7979
await inner.restore()
@@ -85,11 +85,11 @@ async def _():
8585
@reactive.effect
8686
@reactive.event(input.stream_5)
8787
async def _():
88-
async with chat.append_message_context() as outer:
88+
async with chat.message_stream_context() as outer:
8989
await outer.append("Outer start")
9090
await asyncio.sleep(SLEEP_TIME)
9191
await outer.restore()
92-
async with chat.append_message_context() as inner:
92+
async with chat.message_stream_context() as inner:
9393
await inner.append("Inner start")
9494
await asyncio.sleep(SLEEP_TIME)
9595
await inner.append("Inner end")
@@ -112,7 +112,7 @@ async def outer_stream():
112112

113113

114114
async def inner_stream():
115-
async with chat.append_message_context() as stream:
115+
async with chat.message_stream_context() as stream:
116116
await stream.append("Inner start")
117117
await asyncio.sleep(SLEEP_TIME)
118118
await stream.append("Inner progress")

0 commit comments

Comments
 (0)