Skip to content

Commit 802f701

Browse files
committed
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
1 parent c5ca2af commit 802f701

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

litellm/types/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,12 @@ def __init__(
754754
self.function_call = function_call
755755
if tool_calls is not None and isinstance(tool_calls, list):
756756
self.tool_calls = []
757+
current_index = 0
757758
for tool_call in tool_calls:
758759
if isinstance(tool_call, dict):
759760
if tool_call.get("index", None) is None:
760-
tool_call["index"] = 0
761+
tool_call["index"] = current_index
762+
current_index += 1
761763
self.tool_calls.append(ChatCompletionDeltaToolCall(**tool_call))
762764
elif isinstance(tool_call, ChatCompletionDeltaToolCall):
763765
self.tool_calls.append(tool_call)

0 commit comments

Comments
 (0)