The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix tool aws bedrock call index when the function only have optional arg (#13115)
Johnny.H97d89584c137
diff --git a/litellm/llms/bedrock/chat/invoke_handler.py b/litellm/llms/bedrock/chat/invoke_handler.pyindex e33535043d5..b8dac7c3cd7 100644--- a/litellm/llms/bedrock/chat/invoke_handler.py+++ b/litellm/llms/bedrock/chat/invoke_handler.py@@ -1384,7 +1384,9 @@ class AWSEventStreamDecoder:"name": None,"arguments": "{}",},- "index": chunk_data["contentBlockIndex"],+ "index": self.tool_calls_index+ if self.tool_calls_index is not None+ else index,}elif "stopReason" in chunk_data:finish_reason = map_finish_reason(chunk_data.get("stopReason", "stop"))diff --git a/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py b/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.pyindex df3a4d09680..429b1a43896 100644--- a/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py+++ b/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py@@ -81,3 +81,89 @@ def test_transform_tool_calls_index():tool_call_hunk_dict = tool_call_hunk.model_dump()for tool_call in tool_call_hunk_dict["choices"][0]["delta"]["tool_calls"]:assert tool_call["index"] == 1+++def test_transform_tool_calls_index_with_optional_arg_func():+ chunks = [+ {+ "contentBlockIndex": 0,+ "delta": {"text": "To"},+ "p": "abcdefghijklmnopqrstuv",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " get the current time, I"},+ "p": "abcdefghijklmnopqrstuvwxyzABCD",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": ' can use the "get_time"'},+ "p": "abcdefghijkl",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " function. Since the user"},+ "p": "abcdefghijkl",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " didn't specify whether"},+ "p": "abcdefghijklmnopqrstuvw",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " they want UTC time or local time,"},+ "p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " I'll assume they"},+ "p": "abcdefghijkl",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " want the local time. Here's"},+ "p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": " how I"},+ "p": "abcdefghijklmnopqrstuvw",+ },+ {+ "contentBlockIndex": 0,+ "delta": {"text": "'ll make the function call:"},+ "p": "abcdefghijklmnopqrstuvwxyzAB",+ },+ {+ "contentBlockIndex": 0,+ "p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",+ },+ {+ "contentBlockIndex": 1,+ "p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO",+ "start": {+ "toolUse": {+ "name": "get_time",+ "toolUseId": "tooluse_htgmgeJATsKTl4s_LW77sQ",+ }+ },+ },+ {+ "contentBlockIndex": 1,+ "delta": {"toolUse": {"input": ""}},+ "p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV",+ },+ {"contentBlockIndex": 1, "p": "abcdefghijklmnopqrstuvw"},+ {"p": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK", "stopReason": "tool_use"},+ ]+ decoder = AWSEventStreamDecoder(model="test")+ parsed_chunks = []+ for chunk in chunks:+ parsed_chunk = decoder._chunk_parser(chunk)+ parsed_chunks.append(parsed_chunk)+ tool_call_chunks = parsed_chunks[11:14]+ for tool_call_hunk in tool_call_chunks:+ tool_call_hunk_dict = tool_call_hunk.model_dump()+ for tool_call in tool_call_hunk_dict["choices"][0]["delta"]["tool_calls"]:+ assert tool_call["index"] == 0