fix(webui): merge length recovery stream segments
This commit is contained in:
@@ -49,6 +49,7 @@ class MockChannel(BaseChannel):
|
||||
stream_id=None,
|
||||
stream_end=False,
|
||||
resuming=False,
|
||||
merge_next=False,
|
||||
):
|
||||
return await self._send_delta_mock(
|
||||
chat_id,
|
||||
@@ -57,6 +58,7 @@ class MockChannel(BaseChannel):
|
||||
stream_id=stream_id,
|
||||
stream_end=stream_end,
|
||||
resuming=resuming,
|
||||
merge_next=merge_next,
|
||||
)
|
||||
|
||||
|
||||
@@ -92,11 +94,17 @@ def _end(
|
||||
chat_id: str = "chat1",
|
||||
stream_id: str | None = None,
|
||||
resuming: bool = False,
|
||||
merge_next: bool = False,
|
||||
):
|
||||
return outbound_message_for_event(
|
||||
channel="mock",
|
||||
chat_id=chat_id,
|
||||
event=StreamEndEvent(content=content, stream_id=stream_id, resuming=resuming),
|
||||
event=StreamEndEvent(
|
||||
content=content,
|
||||
stream_id=stream_id,
|
||||
resuming=resuming,
|
||||
merge_next=merge_next,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -137,6 +145,7 @@ class TestDeltaCoalescing:
|
||||
stream_id=None,
|
||||
stream_end=False,
|
||||
resuming=False,
|
||||
merge_next=False,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -184,13 +193,19 @@ class TestDeltaCoalescing:
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_end_terminates_coalescing(self, manager, bus):
|
||||
await bus.publish_outbound(_delta("Hello"))
|
||||
await bus.publish_outbound(_end(" world"))
|
||||
await bus.publish_outbound(_end(
|
||||
" world",
|
||||
resuming=True,
|
||||
merge_next=True,
|
||||
))
|
||||
|
||||
first_msg = await bus.consume_outbound()
|
||||
merged, pending = manager._coalesce_stream_deltas(first_msg)
|
||||
|
||||
assert merged.content == "Hello world"
|
||||
assert isinstance(merged.event, StreamEndEvent)
|
||||
assert merged.event.resuming is True
|
||||
assert merged.event.merge_next is True
|
||||
assert len(pending) == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -2818,7 +2818,7 @@ async def test_send_with_retry_no_retry_when_max_is_zero():
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_with_retry_calls_send_delta():
|
||||
"""_send_with_retry should call send_delta for stream delta events."""
|
||||
calls: list[tuple[str, str, str | None, bool, bool]] = []
|
||||
calls: list[tuple[str, str, str | None, bool, bool, bool]] = []
|
||||
|
||||
class _StreamingChannel(BaseChannel):
|
||||
name = "streaming"
|
||||
@@ -2842,8 +2842,9 @@ async def test_send_with_retry_calls_send_delta():
|
||||
stream_id: str | None = None,
|
||||
stream_end: bool = False,
|
||||
resuming: bool = False,
|
||||
merge_next: bool = False,
|
||||
) -> None:
|
||||
calls.append((chat_id, delta, stream_id, stream_end, resuming))
|
||||
calls.append((chat_id, delta, stream_id, stream_end, resuming, merge_next))
|
||||
|
||||
fake_config = SimpleNamespace(
|
||||
channels=ChannelsConfig(send_max_retries=3),
|
||||
@@ -2865,13 +2866,18 @@ async def test_send_with_retry_calls_send_delta():
|
||||
end = outbound_message_for_event(
|
||||
channel="streaming",
|
||||
chat_id="123",
|
||||
event=StreamEndEvent(content="", stream_id="s1", resuming=True),
|
||||
event=StreamEndEvent(
|
||||
content="",
|
||||
stream_id="s1",
|
||||
resuming=True,
|
||||
merge_next=True,
|
||||
),
|
||||
)
|
||||
await mgr._send_with_retry(mgr.channels["streaming"], end)
|
||||
|
||||
assert calls == [
|
||||
("123", "test delta", "s1", False, False),
|
||||
("123", "", "s1", True, True),
|
||||
("123", "test delta", "s1", False, False, False),
|
||||
("123", "", "s1", True, True, True),
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user