fix: prevent duplicate LLM stream snapshots
This commit is contained in:
@@ -66,6 +66,43 @@ class MentorStreamTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(result["answer"], "first second")
|
||||
|
||||
def test_final_full_message_does_not_duplicate_streamed_deltas(self):
|
||||
lines = [
|
||||
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(
|
||||
"mentor_agent.urllib.request.urlopen",
|
||||
return_value=FakeStreamResponse(lines),
|
||||
):
|
||||
chunks = list(
|
||||
stream_with_mentor(
|
||||
self.skill, {}, "question", [], "key",
|
||||
"https://example.test/v1", "model",
|
||||
)
|
||||
)
|
||||
self.assertEqual(chunks, ["first", " second"])
|
||||
|
||||
def test_snapshot_only_stream_emits_only_new_suffix(self):
|
||||
lines = [
|
||||
b'data: {"choices":[{"message":{"content":"first"}}]}\n',
|
||||
b'data: {"choices":[{"message":{"content":"first second"}}]}\n',
|
||||
b"data: [DONE]\n",
|
||||
]
|
||||
with patch(
|
||||
"mentor_agent.urllib.request.urlopen",
|
||||
return_value=FakeStreamResponse(lines),
|
||||
):
|
||||
chunks = list(
|
||||
stream_with_mentor(
|
||||
self.skill, {}, "question", [], "key",
|
||||
"https://example.test/v1", "model",
|
||||
)
|
||||
)
|
||||
self.assertEqual(chunks, ["first", " second"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user