-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(provider): add missing index field to streaming tool_call deltas (#6661) #6692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,6 +307,14 @@ async def _query_stream( | |
| state = ChatCompletionStreamState() | ||
|
|
||
| async for chunk in stream: | ||
| # Fix for #6661: Add missing 'index' field to tool_call deltas | ||
| # Gemini and some OpenAI-compatible proxies omit this field | ||
| if chunk.choices: | ||
| choice = chunk.choices[0] | ||
| if choice.delta and choice.delta.tool_calls: | ||
| for tc in choice.delta.tool_calls: | ||
| if not hasattr(tc, "index") or tc.index is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| tc.index = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding A more robust solution would be to assign a unique index to each tool call. This can be achieved by maintaining a state within If you can confirm that the targeted OpenAI-compatible proxies will only ever stream one tool call at a time, then this fix is sufficient. Otherwise, I strongly recommend implementing the stateful indexing logic to prevent bugs with multiple tool calls. |
||
| try: | ||
| state.handle_chunk(chunk) | ||
| except Exception as e: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.