Fix tool call index assignment in Delta class

- Update tool call index logic to assign sequential indices when missing
- Replace default index=0 behavior with proper sequential assignment
- Maintain OpenAI API compatibility with correct tool call indexing
- Preserve existing behavior for tool calls with explicit indices
- Universal fix benefiting all providers using Delta class
This commit is contained in:
Tim Elfrink 2025-09-15 21:11:31 +02:00
parent c5ca2afec3
commit 802f7011e2

View file

@ -754,10 +754,12 @@ class Delta(OpenAIObject):
self.function_call = function_call
if tool_calls is not None and isinstance(tool_calls, list):
self.tool_calls = []
current_index = 0
for tool_call in tool_calls:
if isinstance(tool_call, dict):
if tool_call.get("index", None) is None:
tool_call["index"] = 0
tool_call["index"] = current_index
current_index += 1
self.tool_calls.append(ChatCompletionDeltaToolCall(**tool_call))
elif isinstance(tool_call, ChatCompletionDeltaToolCall):
self.tool_calls.append(tool_call)