|
82 | 82 |
|
83 | 83 | ChunkOption = Literal["start", "end", True, False] |
84 | 84 |
|
85 | | -PendingMessage = Tuple[Any, ChunkOption, Union[str, None]] |
| 85 | +PendingMessage = Tuple[ |
| 86 | + Any, |
| 87 | + ChunkOption, |
| 88 | + Literal["append", "replace"], |
| 89 | + Union[str, None], |
| 90 | +] |
86 | 91 |
|
87 | 92 |
|
88 | 93 | @add_example(ex_dir="../templates/chat/starters/hello") |
@@ -576,7 +581,7 @@ async def append_message( |
576 | 581 | """ |
577 | 582 | # If we're in a stream, queue the message |
578 | 583 | if self._current_stream_id: |
579 | | - self._pending_messages.append((message, False, None)) |
| 584 | + self._pending_messages.append((message, False, "append", None)) |
580 | 585 | return |
581 | 586 |
|
582 | 587 | msg = normalize_message(message) |
@@ -685,7 +690,7 @@ async def _append_message_chunk( |
685 | 690 | ) -> None: |
686 | 691 | # If currently we're in a *different* stream, queue the message chunk |
687 | 692 | if self._current_stream_id and self._current_stream_id != stream_id: |
688 | | - self._pending_messages.append((message, chunk, stream_id)) |
| 693 | + self._pending_messages.append((message, chunk, operation, stream_id)) |
689 | 694 | return |
690 | 695 |
|
691 | 696 | self._current_stream_id = stream_id |
@@ -876,12 +881,15 @@ async def _append_message_stream( |
876 | 881 | async def _flush_pending_messages(self): |
877 | 882 | pending = self._pending_messages |
878 | 883 | self._pending_messages = [] |
879 | | - for msg, chunk, stream_id in pending: |
| 884 | + for msg, chunk, operation, stream_id in pending: |
880 | 885 | if chunk is False: |
881 | 886 | await self.append_message(msg) |
882 | 887 | else: |
883 | 888 | await self._append_message_chunk( |
884 | | - msg, chunk=chunk, stream_id=cast(str, stream_id) |
| 889 | + msg, |
| 890 | + chunk=chunk, |
| 891 | + operation=operation, |
| 892 | + stream_id=cast(str, stream_id), |
885 | 893 | ) |
886 | 894 |
|
887 | 895 | # Send a message to the UI |
|
0 commit comments