fix(router): honor router default drop_params when skipping clip-refusing Decisions deployments

This commit is contained in:
mateo-berri 2026-10-30 23:14:32 -07:00
parent 4ff23fbde9
commit 672bf1116a
2 changed files with 38 additions and 5 deletions

View file

@ -4152,13 +4152,16 @@ class Router(DeprecatedRouterMembers):
raise e.original_exception from e
raise e
def _active_default_litellm_params(self) -> Mapping[str, object]:
default_params: Final = _REQUEST_KWARGS_ADAPTER.validate_python(self._core_default_litellm_params)
return {key: value for key, value in default_params.items() if value is not None}
def _params_sent_to_deployment(
self, request_kwargs: Mapping[str, object], deployment: Deployment | None
) -> Mapping[str, object]:
"""The request as the deployment received it, merged in the order _update_kwargs_with_deployment applies."""
deployment_params: Final = deployment.litellm_params.model_dump(exclude_none=True) if deployment else {}
default_params: Final = _REQUEST_KWARGS_ADAPTER.validate_python(self._core_default_litellm_params)
defaults: Final = {key: value for key, value in default_params.items() if value is not None}
defaults: Final = self._active_default_litellm_params()
deployment_tool_choice: Final = (
{"tool_choice": deployment_params["tool_choice"]}
if deployment_params.get("tool_choice") is not None
@ -14912,9 +14915,8 @@ class Router(DeprecatedRouterMembers):
)
return False
@staticmethod
def _without_decisions_deployments_refusing_media(
healthy_deployments: _RouteDeploymentsT, group: str, request_kwargs: Mapping[str, object] | None
self, healthy_deployments: _RouteDeploymentsT, group: str, request_kwargs: Mapping[str, object] | None
) -> _RouteDeploymentsT:
call_kwargs: Final = request_kwargs or {}
audio: Final = bool(call_kwargs.get("audio"))
@ -14926,13 +14928,14 @@ class Router(DeprecatedRouterMembers):
):
return healthy_deployments
sent_kwargs: Final = {**self._active_default_litellm_params(), **call_kwargs}
deployments_taking_media: Final = [
deployment
for deployment in healthy_deployments
if not Router._decisions_deployment_refuses_media(
cast(DeploymentTypedDict, deployment), # cast-ok: router candidates use the deployment shape
group,
call_kwargs,
sent_kwargs,
audio=audio,
videos=videos,
)

View file

@ -3973,6 +3973,36 @@ async def test_clips_to_a_group_whose_only_taker_is_cooling_down_are_refused_rat
assert len(route.calls) == sent_before_clips
@pytest.mark.asyncio
@pytest.mark.parametrize("surface", tuple(_MEDIA_SURFACES))
async def test_a_router_default_drop_params_overrides_a_deployment_when_choosing_who_takes_clips(
respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, local_model_cost_map: None, surface: str
) -> None:
monkeypatch.setattr(litellm, "drop_params", False)
respx_mock.post("https://openrouter.ai/api/alpha/decisions").respond(json=_RESPONSE)
unlisted: Final = "openrouter/example/omni-preview"
router: Final = litellm.Router(
model_list=[
_group_member("g", unlisted, "drops", 1, {}, drop_params=True),
_group_member("g", unlisted, "takes", 0, {"supports_audio_input": True}),
],
default_litellm_params={"drop_params": False},
)
call: Final = getattr(router, surface)
async def send(**params: object) -> object:
response: Final = call(model="g", **_MEDIA_SURFACES[surface], audio=_AUDIO_CLIPS, **params)
return await response if asyncio.iscoroutine(response) else response
await send()
assert respx_mock.calls.last.request.headers["authorization"] == "Bearer takes"
assert json.loads(respx_mock.calls.last.request.content)["audio"] == list(_AUDIO_CLIPS)
await send(drop_params=True)
assert respx_mock.calls.last.request.headers["authorization"] == "Bearer drops"
assert "audio" not in json.loads(respx_mock.calls.last.request.content)
@pytest.mark.asyncio
async def test_a_deployment_that_turns_audio_off_is_refused_or_dropped_even_when_the_cost_map_allows_it(
respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch, local_model_cost_map: None