fix(bedrock/): add generic support for tool calling on bedrock models

Closes https://github.com/BerriAI/litellm/issues/11430
This commit is contained in:
Krrish Dholakia 2025-06-05 23:36:50 -07:00
parent 603bd73a17
commit 398fef8391
2 changed files with 51 additions and 0 deletions

View File

@ -105,6 +105,8 @@ class AmazonConverseConfig(BaseConfig):
}
def get_supported_openai_params(self, model: str) -> List[str]:
from litellm.utils import supports_function_calling
supported_params = [
"max_tokens",
"max_completion_tokens",
@ -137,6 +139,9 @@ class AmazonConverseConfig(BaseConfig):
or base_model.startswith("meta.llama3-2")
or base_model.startswith("meta.llama3-3")
or base_model.startswith("amazon.nova")
or supports_function_calling(
model=model, custom_llm_provider=self.custom_llm_provider
)
):
supported_params.append("tools")

View File

@ -3141,3 +3141,49 @@ async def test_bedrock_max_completion_tokens(model: str):
}
def test_bedrock_meta_llama_function_calling():
"""
Tests that:
- meta llama models support function calling
"""
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
},
},
"required": ["location"],
},
},
}
]
messages = [
{
"role": "user",
"content": "What's the weather like in Boston today in fahrenheit?",
}
]
request_args = {
"messages": messages,
"tools": tools,
"model": "bedrock/us.meta.llama4-scout-17b-instruct-v1:0",
}
response = completion(**request_args)
print(response)