Skip to content
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

fix: prevent tools override #8273

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions litellm/llms/bedrock/chat/converse_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,19 @@ def map_openai_params(
json_schema=json_schema,
schema_name=schema_name if schema_name != "" else "json_tool_call",
)
optional_params["tools"] = [_tool]

optional_params = self._add_tools_to_optional_params(
optional_params=optional_params, tools=[_tool]
)

if litellm.utils.supports_tool_choice(
model=model, custom_llm_provider=self.custom_llm_provider
):
optional_params["tool_choice"] = ToolChoiceValuesBlock(
tool=SpecificToolChoiceBlock(
name=schema_name if schema_name != "" else "json_tool_call"
)

)
optional_params["json_mode"] = True
if non_default_params.get("stream", False) is True:
Expand All @@ -256,7 +261,9 @@ def map_openai_params(
if param == "top_p":
optional_params["topP"] = value
if param == "tools":
optional_params["tools"] = value
optional_params = self._add_tools_to_optional_params(
optional_params=optional_params, tools=value # type: ignore
)
if param == "tool_choice":
_tool_choice_value = self.map_tool_choice_values(
model=model, tool_choice=value, drop_params=drop_params # type: ignore
Expand Down Expand Up @@ -735,3 +742,15 @@ def validate_environment(
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
return headers

def _add_tools_to_optional_params(
self, optional_params: dict, tools: List[ChatCompletionToolParam]
) -> dict:
if "tools" not in optional_params:
optional_params["tools"] = tools
else:
optional_params["tools"] = [
*optional_params["tools"],
*tools,
]
return optional_params