mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
address greptile sse recovery feedback
This commit is contained in:
parent
e511018c75
commit
328549d87a
2 changed files with 33 additions and 0 deletions
|
|
@ -69,6 +69,11 @@ def record_output_text_delta_chunk(
|
|||
output_items: Dict[int, Dict[str, Any]],
|
||||
text_only_items: Dict[int, Dict[str, Any]],
|
||||
) -> None:
|
||||
"""Accumulate an OUTPUT_TEXT_DELTA chunk into ``text_only_items``.
|
||||
|
||||
Real OUTPUT_ITEM_DONE events already captured in ``output_items`` take
|
||||
precedence at the same ``output_index``.
|
||||
"""
|
||||
text_delta = parsed_chunk.get("delta")
|
||||
if not isinstance(text_delta, str):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -86,6 +86,34 @@ def test_text_delta_chunks_are_accumulated():
|
|||
assert text_only_items[0]["content"][0]["text"] == "Hello"
|
||||
|
||||
|
||||
def test_text_done_replaces_accumulated_delta_with_final_text():
|
||||
output_items: dict = {}
|
||||
text_only_items: dict = {}
|
||||
|
||||
record_output_text_delta_chunk(
|
||||
parsed_chunk={
|
||||
"type": "response.output_text.delta",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"delta": "partial",
|
||||
},
|
||||
output_items=output_items,
|
||||
text_only_items=text_only_items,
|
||||
)
|
||||
record_output_text_chunk(
|
||||
parsed_chunk={
|
||||
"type": "response.output_text.done",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"text": "final",
|
||||
},
|
||||
output_items=output_items,
|
||||
text_only_items=text_only_items,
|
||||
)
|
||||
|
||||
assert text_only_items[0]["content"][0]["text"] == "final"
|
||||
|
||||
|
||||
def test_text_delta_with_invalid_delta_is_ignored():
|
||||
output_items: dict = {}
|
||||
text_only_items: dict = {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue