mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
Fix converse handling for parallel_tool_calls
This commit is contained in:
parent
e3fc3a4cec
commit
7d338ae89b
2 changed files with 101 additions and 3 deletions
|
|
@ -511,6 +511,7 @@ class AmazonConverseConfig(BaseConfig):
|
|||
"response_format",
|
||||
"requestMetadata",
|
||||
"service_tier",
|
||||
"parallel_tool_calls",
|
||||
]
|
||||
|
||||
if (
|
||||
|
|
@ -913,6 +914,13 @@ class AmazonConverseConfig(BaseConfig):
|
|||
)
|
||||
if _tool_choice_value is not None:
|
||||
optional_params["tool_choice"] = _tool_choice_value
|
||||
if param == "parallel_tool_calls":
|
||||
disable_parallel = not value
|
||||
optional_params["_parallel_tool_use_config"] = {
|
||||
"tool_choice": {
|
||||
"disable_parallel_tool_use": disable_parallel
|
||||
}
|
||||
}
|
||||
if param == "thinking":
|
||||
optional_params["thinking"] = value
|
||||
elif param == "reasoning_effort" and isinstance(value, str):
|
||||
|
|
@ -1207,6 +1215,17 @@ class AmazonConverseConfig(BaseConfig):
|
|||
k: v for k, v in inference_params.items() if k in total_supported_params
|
||||
}
|
||||
|
||||
# Handle parallel_tool_calls configuration
|
||||
parallel_tool_use_config = additional_request_params.pop("_parallel_tool_use_config", None)
|
||||
if parallel_tool_use_config is not None and is_claude_4_5_on_bedrock(model):
|
||||
for key, value in parallel_tool_use_config.items():
|
||||
if key in additional_request_params and isinstance(additional_request_params[key], dict) and isinstance(value, dict):
|
||||
additional_request_params[key].update(value)
|
||||
else:
|
||||
additional_request_params[key] = value
|
||||
|
||||
additional_request_params.pop("parallel_tool_calls", None)
|
||||
|
||||
# Only set the topK value in for models that support it
|
||||
additional_request_params.update(
|
||||
self._handle_top_k_value(model, inference_params)
|
||||
|
|
|
|||
|
|
@ -2616,11 +2616,11 @@ def test_empty_assistant_message_handling():
|
|||
empty or whitespace-only content with a placeholder to prevent AWS Bedrock
|
||||
Converse API 400 Bad Request errors.
|
||||
"""
|
||||
# Import the litellm module that factory.py uses to ensure we patch the correct reference
|
||||
import litellm.litellm_core_utils.prompt_templates.factory as factory_module
|
||||
from litellm.litellm_core_utils.prompt_templates.factory import (
|
||||
_bedrock_converse_messages_pt,
|
||||
)
|
||||
# Import the litellm module that factory.py uses to ensure we patch the correct reference
|
||||
import litellm.litellm_core_utils.prompt_templates.factory as factory_module
|
||||
|
||||
# Test case 1: Empty string content - test with modify_params=True to prevent merging
|
||||
messages = [
|
||||
|
|
@ -3135,7 +3135,12 @@ def test_native_structured_output_no_fake_stream():
|
|||
|
||||
def test_transform_request_with_output_config():
|
||||
"""Test that outputConfig flows through _transform_request_helper into the final request."""
|
||||
from litellm.types.llms.bedrock import OutputConfigBlock, OutputFormat, OutputFormatStructure, JsonSchemaDefinition
|
||||
from litellm.types.llms.bedrock import (
|
||||
JsonSchemaDefinition,
|
||||
OutputConfigBlock,
|
||||
OutputFormat,
|
||||
OutputFormatStructure,
|
||||
)
|
||||
|
||||
config = AmazonConverseConfig()
|
||||
|
||||
|
|
@ -3377,6 +3382,80 @@ def test_output_config_applies_additional_properties():
|
|||
|
||||
|
||||
|
||||
_TOOL_PARAM = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get the weather",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "The location to get weather for",
|
||||
}
|
||||
},
|
||||
"required": ["location"],
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_parallel_tool_calls_newer_model_adds_disable_flag():
|
||||
"""Newer Claude models (4.5+) should get disable_parallel_tool_use in additionalModelRequestFields."""
|
||||
config = AmazonConverseConfig()
|
||||
model = "anthropic.claude-sonnet-4-5-20250929-v1:0"
|
||||
messages = [{"role": "user", "content": "What's the weather in SF and NYC?"}]
|
||||
|
||||
optional_params = config.map_openai_params(
|
||||
non_default_params={"parallel_tool_calls": False, "tools": _TOOL_PARAM},
|
||||
optional_params={},
|
||||
model=model,
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
request_data = config.transform_request(
|
||||
model=model,
|
||||
messages=messages,
|
||||
optional_params=optional_params,
|
||||
litellm_params={},
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert "additionalModelRequestFields" in request_data
|
||||
assert "tool_choice" in request_data["additionalModelRequestFields"]
|
||||
assert request_data["additionalModelRequestFields"]["tool_choice"]["disable_parallel_tool_use"] is True
|
||||
assert "parallel_tool_calls" not in request_data["additionalModelRequestFields"]
|
||||
|
||||
|
||||
def test_parallel_tool_calls_older_model_drops_disable_flag():
|
||||
"""Older Claude models (pre-4.5) must NOT receive disable_parallel_tool_use — Bedrock rejects it."""
|
||||
config = AmazonConverseConfig()
|
||||
model = "anthropic.claude-3-5-sonnet-20241022-v2:0"
|
||||
messages = [{"role": "user", "content": "What's the weather in SF and NYC?"}]
|
||||
|
||||
optional_params = config.map_openai_params(
|
||||
non_default_params={"parallel_tool_calls": False, "tools": _TOOL_PARAM},
|
||||
optional_params={},
|
||||
model=model,
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
request_data = config.transform_request(
|
||||
model=model,
|
||||
messages=messages,
|
||||
optional_params=optional_params,
|
||||
litellm_params={},
|
||||
headers={},
|
||||
)
|
||||
|
||||
additional = request_data.get("additionalModelRequestFields", {})
|
||||
assert "tool_choice" not in additional
|
||||
assert "parallel_tool_calls" not in additional
|
||||
|
||||
|
||||
class TestBedrockMinThinkingBudgetTokens:
|
||||
"""Test that thinking.budget_tokens is clamped to the Bedrock minimum (1024)."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue