@@ -590,46 +590,8 @@ async def append_message(
590590 icon = icon ,
591591 )
592592
593- async def append_message_chunk (self , message_chunk : Any ):
594- """
595- Append a message chunk to the current message stream.
596-
597- Append a chunk of message content to either a stream started with
598- `.message_stream()` or an active `.append_message_stream()`.
599-
600- Parameters
601- ----------
602- message_chunk
603- A message chunk to inject.
604-
605- Note
606- ----
607- A useful pattern for displaying tool calls in a chat is for the tools to display
608- content using an "inner" `.message_stream()` while the response generation is
609- happening in an "outer" `.append_message_stream()`. This allows the inner stream
610- to display "ephemeral" content, then eventually show a final state with
611- `.append_message_chunk(operation="replace")`.
612-
613- Raises
614- ------
615- ValueError
616- If there is active stream (i.e., no `.message_stream()` or
617- `.append_message_stream()`)
618- """
619- stream_id = self ._current_stream_id
620- if stream_id is None :
621- raise ValueError (
622- "Can't .append_message_chunk() without an active message stream. "
623- "Use .message_stream() or .append_message_stream() to start one."
624- )
625-
626- return await self ._append_message_chunk (
627- message_chunk ,
628- stream_id = stream_id ,
629- )
630-
631593 @asynccontextmanager
632- async def message_stream (self ):
594+ async def append_message_context (self ):
633595 """
634596 Message stream context manager.
635597
@@ -639,13 +601,13 @@ async def message_stream(self):
639601 Yields
640602 ------
641603 :
642- A `MessageStream` instance with a method for `.append()`ing message chunks
643- and a method for `.restore()`ing the stream back to it's initial state.
604+ A `MessageStream` class instance, which has a method for `.append()`ing
605+ and `.restore()`ing the stream back to it's initial state.
644606
645607 Note
646608 ----
647609 A useful pattern for displaying tool calls in a chat interface is for the
648- tool to display using `.message_stream ()` while the the response generation
610+ tool to display using `.append_message_context ()` while the the response generation
649611 is happening through `.append_message_stream()`. This allows the inner stream
650612 to display "ephemeral" content, then eventually show a final state
651613 with `.append_message_chunk(operation="replace")`.
@@ -1493,7 +1455,9 @@ def chat_ui(
14931455
14941456
14951457class MessageStream :
1496- """"""
1458+ """
1459+ An object to yield from a `.append_message_context()` context manager.
1460+ """
14971461
14981462 def __init__ (self , chat : Chat , stream_id : str ):
14991463 self ._chat = chat
0 commit comments