Skip to content

Commit e4ce090

Browse files
Yaohua-LeoYaohua-LeoSoulter
authored
fix(provider): add missing index field to streaming tool_call deltas (#6661) (#6692)
* fix(provider): add missing index field to streaming tool_call deltas - Fix #6661: Streaming tool_call arguments lost when OpenAI-compatible proxy omits index field - Gemini and some proxies (e.g. Continue) don't include index field in tool_call deltas - Add default index=0 when missing to prevent ChatCompletionStreamState.handle_chunk() from rejecting chunks Fixes #6661 * fix(provider): use enumerate for multi-tool-call index assignment - Use enumerate() to assign correct index based on list position - Iterate over all choices (not just the first) for completeness - Addresses review feedback from sourcery-ai and gemini-code-assist --------- Co-authored-by: Yaohua-Leo <3067173925@qq.com> Co-authored-by: Soulter <905617992@qq.com>
1 parent 11c7591 commit e4ce090

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

astrbot/core/provider/sources/openai_source.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,15 @@ async def _query_stream(
334334
choice = chunk.choices[0]
335335
delta = choice.delta
336336

337-
# siliconflow workaround
338337
if dtcs := delta.tool_calls:
339-
for tc in dtcs:
338+
for idx, tc in enumerate(dtcs):
339+
# siliconflow workaround
340340
if tc.function and tc.function.arguments:
341341
tc.type = "function"
342+
# Fix for #6661: Add missing 'index' field to tool_call deltas
343+
# Gemini and some OpenAI-compatible proxies omit this field
344+
if not hasattr(tc, "index") or tc.index is None:
345+
tc.index = idx
342346
try:
343347
state.handle_chunk(chunk)
344348
except Exception as e:

0 commit comments

Comments
 (0)