-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
fix(bedrock): accept tool_choice="any" on the Converse adapter #38047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
likalight
wants to merge
1
commit into
BerriAI:main
Choose a base branch
from
likalight:fix/bedrock-tool-choice-any
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/test_litellm/llms/bedrock/chat/test_bedrock_tool_choice_any.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """`tool_choice="any"` is Bedrock's own native value and must be accepted.""" | ||
|
|
||
| import pytest | ||
|
|
||
| import litellm | ||
| from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig | ||
|
|
||
| MODEL = "anthropic.claude-3-haiku-20240307-v1:0" | ||
|
|
||
|
|
||
| class TestBedrockToolChoiceAny: | ||
| def setup_method(self): | ||
| self.config = AmazonConverseConfig() | ||
|
|
||
| @pytest.mark.parametrize("tool_choice", ["required", "any"]) | ||
| def test_required_and_any_both_map_to_bedrock_any(self, tool_choice): | ||
| result = self.config.map_tool_choice_values(model=MODEL, tool_choice=tool_choice, drop_params=False) | ||
|
|
||
| assert result == {"any": {}} | ||
|
|
||
| def test_auto_is_unchanged(self): | ||
| result = self.config.map_tool_choice_values(model=MODEL, tool_choice="auto", drop_params=False) | ||
|
|
||
| assert result == {"auto": {}} | ||
|
|
||
| def test_specific_tool_is_unchanged(self): | ||
| result = self.config.map_tool_choice_values( | ||
| model=MODEL, | ||
| tool_choice={"type": "function", "function": {"name": "get_weather"}}, | ||
| drop_params=False, | ||
| ) | ||
|
|
||
| assert result == {"tool": {"name": "get_weather"}} | ||
|
|
||
| def test_unknown_value_still_raises_and_lists_any(self): | ||
| with pytest.raises(litellm.utils.UnsupportedParamsError) as exc_info: | ||
| self.config.map_tool_choice_values(model=MODEL, tool_choice="definitely_not_supported", drop_params=False) | ||
|
|
||
| # The error text is the discoverability surface for these values. | ||
| assert "'any'" in str(exc_info.value) | ||
|
|
||
| def test_none_still_drops_when_drop_params_is_set(self): | ||
| assert self.config.map_tool_choice_values(model=MODEL, tool_choice="none", drop_params=True) is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments here and beside the error-message assertion in the new test restate straightforward code rather than explaining complex behavior, adding maintenance noise that can drift from the implementation.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!