fix: prevent duplicate LLM stream snapshots
This commit is contained in:
@@ -45,6 +45,23 @@ class ReviewAssistantStreamingTests(unittest.TestCase):
|
||||
stream_review_assistant({}, "question", [], "key", "https://example.test/v1", "model")
|
||||
)
|
||||
|
||||
def test_final_full_message_does_not_duplicate_streamed_deltas(self):
|
||||
response = StreamingResponse(
|
||||
[
|
||||
b'data: {"choices":[{"delta":{"content":"first"}}]}\n',
|
||||
b'data: {"choices":[{"delta":{"content":" second"}}]}\n',
|
||||
b'data: {"choices":[{"message":{"content":"first second"}}]}\n',
|
||||
b"data: [DONE]\n",
|
||||
]
|
||||
)
|
||||
with patch("assistant_agent.urllib.request.urlopen", return_value=response):
|
||||
chunks = list(
|
||||
stream_review_assistant(
|
||||
{}, "question", [], "key", "https://example.test/v1", "model"
|
||||
)
|
||||
)
|
||||
self.assertEqual(chunks, ["first", " second"])
|
||||
|
||||
def test_ndjson_event_writer_flushes_complete_line(self):
|
||||
handler = RequestHandler.__new__(RequestHandler)
|
||||
handler.wfile = io.BytesIO()
|
||||
|
||||
Reference in New Issue
Block a user