From e4ce090db2ea38bfc05f4e36597662ff1a77d89a Mon Sep 17 00:00:00 2001 From: LIU Yaohua <12531035@mail.sustech.edu.cn> Date: Wed, 25 Mar 2026 18:31:35 +0800 Subject: [PATCH] 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> --- astrbot/core/provider/sources/openai_source.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index d64feb5a0..68fad067b 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -334,11 +334,15 @@ class ProviderOpenAIOfficial(Provider): choice = chunk.choices[0] delta = choice.delta - # siliconflow workaround if dtcs := delta.tool_calls: - for tc in dtcs: + for idx, tc in enumerate(dtcs): + # siliconflow workaround if tc.function and tc.function.arguments: tc.type = "function" + # Fix for #6661: Add missing 'index' field to tool_call deltas + # Gemini and some OpenAI-compatible proxies omit this field + if not hasattr(tc, "index") or tc.index is None: + tc.index = idx try: state.handle_chunk(chunk) except Exception as e: