fix: merge duplicate streaming tool call deltas#3438
Closed
fengjikui wants to merge 1 commit into
Closed
Conversation
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3201.
Summary
Streaming tool call deltas can contain multiple entries for the same
indexin a single chunk. The previous accumulator stored the first list delta as-is when the field was missing from the accumulator, so duplicate index entries from that initial chunk stayed split apart. A later delta for the same index then merged into the first physical list item, leaving earlier argument fragments stranded in a second item.This changes list accumulation to use the same index-aware merge logic when a list field is first created, and shares that behavior between the chat and assistants streaming accumulators. It also adds a regression test covering duplicate
tool_calls[0]entries in the initial accumulated list.Validation
env -u ALL_PROXY -u HTTPS_PROXY -u HTTP_PROXY -u all_proxy -u https_proxy -u http_proxy .venv/bin/python -m pytest tests/lib/test_streaming_deltas.py tests/lib/chat/test_completions_streaming.py -q.venv/bin/python -m ruff format --check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py.venv/bin/python -m ruff check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py.venv/bin/python -m mypy src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.pygit diff --check