mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix: honor Bedrock tag routing constraints
This commit is contained in:
parent
455879c4e5
commit
6183bc25a1
2 changed files with 66 additions and 1 deletions
|
|
@ -699,8 +699,16 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
|
|||
chain_tag_filtering: Final[object] = (
|
||||
_chain_tag_filtering_override(router, model, deployments) if isinstance(model, str) else None
|
||||
)
|
||||
router_settings_override: Final[object] = request_data.get("router_settings_override")
|
||||
override_tag_filtering: Final[object] = (
|
||||
router_settings_override.get("enable_tag_filtering")
|
||||
if isinstance(router_settings_override, Mapping)
|
||||
else None
|
||||
)
|
||||
effective_tag_filtering: Final = (
|
||||
chain_tag_filtering
|
||||
True
|
||||
if override_tag_filtering is True
|
||||
else chain_tag_filtering
|
||||
if isinstance(chain_tag_filtering, bool)
|
||||
else getattr(router, "enable_tag_filtering", False)
|
||||
)
|
||||
|
|
@ -757,6 +765,8 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
|
|||
bool(header_strings) and has_regex_deployments and not required_set
|
||||
)
|
||||
if not has_positive_filter:
|
||||
if required_set or excluded_set:
|
||||
return candidate_deployments
|
||||
default_deployments: Final = [
|
||||
deployment for deployment in candidate_deployments if "default" in _deployment_tags(deployment)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -294,6 +294,61 @@ def test_bedrock_guardrail_ignores_client_tag_filtering_override(monkeypatch: py
|
|||
)
|
||||
|
||||
|
||||
def test_bedrock_guardrail_honors_router_settings_tag_filtering_override(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.proxy import proxy_server
|
||||
|
||||
router = MagicMock()
|
||||
router.enable_tag_filtering = False
|
||||
router.get_model_list.return_value = [
|
||||
{
|
||||
"litellm_params": {"custom_llm_provider": "openai", "tags": ["slow"]},
|
||||
"model_info": {},
|
||||
},
|
||||
{
|
||||
"litellm_params": {"custom_llm_provider": "bedrock", "tags": ["fast"]},
|
||||
"model_info": {},
|
||||
},
|
||||
]
|
||||
monkeypatch.setattr(proxy_server, "llm_router", router)
|
||||
|
||||
assert (
|
||||
BedrockGuardrail._get_bedrock_api_key(
|
||||
{
|
||||
"model": "shared-alias",
|
||||
"api_key": "bedrock-key",
|
||||
"router_settings_override": {"enable_tag_filtering": True},
|
||||
"metadata": {"tags": ["fast"]},
|
||||
}
|
||||
)
|
||||
== "bedrock-key"
|
||||
)
|
||||
|
||||
|
||||
def test_bedrock_guardrail_keeps_all_required_tag_matches(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.proxy import proxy_server
|
||||
|
||||
router = MagicMock()
|
||||
router.enable_tag_filtering = True
|
||||
router.get_model_list.return_value = [
|
||||
{
|
||||
"litellm_params": {"custom_llm_provider": "bedrock", "tags": ["required", "default"]},
|
||||
"model_info": {},
|
||||
},
|
||||
{
|
||||
"litellm_params": {"custom_llm_provider": "openai", "tags": ["required"]},
|
||||
"model_info": {},
|
||||
},
|
||||
]
|
||||
monkeypatch.setattr(proxy_server, "llm_router", router)
|
||||
|
||||
assert (
|
||||
BedrockGuardrail._router_allows_bedrock(
|
||||
{"model": "shared-alias", "metadata": {"tags": ["&required"]}}
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bedrock_guardrail_async_sync_strategy_uses_unfiltered_pool(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.proxy import proxy_server
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue