mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(anthropic): omit tool_choice when additional_drop_params drops tools
This commit is contained in:
parent
6ae64adfd5
commit
0150e87bf7
2 changed files with 26 additions and 2 deletions
|
|
@ -315,9 +315,10 @@ def _build_responses_kwargs(
|
|||
request_data["temperature"] = temperature
|
||||
if thinking:
|
||||
request_data["thinking"] = thinking
|
||||
if tool_choice:
|
||||
drops_tools: Final = "tools" in drop_policy(forwarded_kwargs).additional_drop_params
|
||||
if tool_choice and not drops_tools:
|
||||
request_data["tool_choice"] = tool_choice
|
||||
if tools and "tools" not in drop_policy(forwarded_kwargs).additional_drop_params:
|
||||
if tools and not drops_tools:
|
||||
request_data["tools"] = tools
|
||||
if top_p is not None:
|
||||
request_data["top_p"] = top_p
|
||||
|
|
|
|||
|
|
@ -939,6 +939,29 @@ async def test_additional_drop_params_tools_sends_no_tools_even_beside_one_opena
|
|||
assert "tools" not in json.loads(upstream.calls.last.request.content)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"tool_choice",
|
||||
[{"type": "tool", "name": "web_fetch"}, {"type": "tool", "name": "bash"}, {"type": "any"}],
|
||||
ids=["forcing-a-tool-openai-cannot-run", "forcing-a-client-tool", "forcing-any-tool"],
|
||||
)
|
||||
async def test_additional_drop_params_tools_sends_no_tool_choice_forcing_a_dropped_tool(
|
||||
respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, tool_choice: Mapping[str, object]
|
||||
):
|
||||
upstream: Final = await _openai_request_for(
|
||||
respx_mock,
|
||||
monkeypatch,
|
||||
[WEB_FETCH, TYPED_BASH],
|
||||
drop_params=True,
|
||||
additional_drop_params=["tools"],
|
||||
tool_choice=dict(tool_choice),
|
||||
)
|
||||
|
||||
sent: Final = json.loads(upstream.calls.last.request.content)
|
||||
assert "tools" not in sent
|
||||
assert "tool_choice" not in sent
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_tool_openai_cannot_run_answers_400_before_any_openai_call_without_drop_params(
|
||||
respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue