Skip to content

Commit c5ca2af

Browse files
committed
Add test for tool call sequential index assignment
- Test multiple tool calls without explicit indices receive sequential indices - Verify Delta class assigns indices 0, 1, 2... instead of defaulting all to 0 - Add comprehensive assertions for tool call details preservation - Cover provider-agnostic streaming response scenarios
1 parent 321d529 commit c5ca2af

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/litellm_utils_tests/test_utils.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,3 +2326,53 @@ def test_get_whitelisted_models():
23262326
file.write(f"{model}\n")
23272327

23282328
print("whitelisted_models written to whitelisted_bedrock_models.txt")
2329+
2330+
2331+
def test_delta_tool_calls_sequential_indices():
2332+
"""
2333+
Test that multiple tool calls without explicit indices receive sequential indices.
2334+
2335+
When providers don't include index fields in tool calls, the Delta class
2336+
should automatically assign sequential indices (0, 1, 2, ...) instead of
2337+
defaulting all tool calls to index=0.
2338+
"""
2339+
import json
2340+
from litellm.types.utils import Delta
2341+
2342+
# Simulate tool calls from streaming responses without explicit indices
2343+
tool_calls_without_indices = [
2344+
{
2345+
"id": "call_1",
2346+
"function": {
2347+
"name": "get_weather_for_dallas",
2348+
"arguments": json.dumps({})
2349+
},
2350+
"type": "function",
2351+
# Note: no "index" field - simulates provider response
2352+
},
2353+
{
2354+
"id": "call_2",
2355+
"function": {
2356+
"name": "get_weather_precise",
2357+
"arguments": json.dumps({"location": "Dallas, TX"})
2358+
},
2359+
"type": "function",
2360+
# Note: no "index" field - simulates provider response
2361+
}
2362+
]
2363+
2364+
# Create Delta object as LiteLLM would when processing streaming response
2365+
delta = Delta(
2366+
content=None,
2367+
tool_calls=tool_calls_without_indices
2368+
)
2369+
2370+
# Verify tool calls have sequential indices
2371+
assert delta.tool_calls is not None, "Tool calls should not be None"
2372+
assert len(delta.tool_calls) == 2
2373+
assert delta.tool_calls[0].index == 0, f"First tool call should have index 0, got {delta.tool_calls[0].index}"
2374+
assert delta.tool_calls[1].index == 1, f"Second tool call should have index 1, got {delta.tool_calls[1].index}"
2375+
2376+
# Verify tool call details are preserved
2377+
assert delta.tool_calls[0].function.name == "get_weather_for_dallas"
2378+
assert delta.tool_calls[1].function.name == "get_weather_precise"

0 commit comments

Comments
 (0)