mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(policy): avoid duplicate provider resolution
This commit is contained in:
parent
28a18ee65d
commit
7344870044
2 changed files with 32 additions and 1 deletions
|
|
@ -61,7 +61,11 @@ class AiPolicySuggester:
|
|||
system_prompt: Final = self._build_system_prompt(templates)
|
||||
user_prompt: Final = self._build_user_prompt(attack_examples, description)
|
||||
model = model or DEFAULT_COMPETITOR_DISCOVERY_MODEL
|
||||
supported_params: Final = litellm.get_supported_openai_params(model=model)
|
||||
custom_llm_provider: Final = model.split("/", 1)[0] if "/" in model else None
|
||||
supported_params: Final = litellm.get_supported_openai_params(
|
||||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
if supported_params is not None and "tools" not in supported_params:
|
||||
raise ProxyException(
|
||||
message=(f"AI policy suggestion requires tool calling; model '{model}' does not support it"),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import pytest
|
|||
|
||||
import litellm
|
||||
|
||||
from litellm.proxy._types import ProxyException
|
||||
from litellm.proxy.management_endpoints.policy_endpoints.ai_policy_suggester import (
|
||||
SUGGEST_TOOL,
|
||||
AiPolicySuggester,
|
||||
|
|
@ -247,6 +248,32 @@ class TestAiPolicySuggester:
|
|||
assert call_kwargs["messages"][1]["role"] == "user"
|
||||
|
||||
|
||||
class TestSuggesterRejectsModelsWithoutToolCalling:
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_tools_less_model_is_rejected(self, local_model_cost_map):
|
||||
with pytest.raises(ProxyException) as exc:
|
||||
await AiPolicySuggester().suggest(
|
||||
templates=SAMPLE_TEMPLATES,
|
||||
attack_examples=["Ignore all previous instructions"],
|
||||
description="Block prompt injection attempts",
|
||||
model="perplexity/sonar",
|
||||
)
|
||||
|
||||
assert int(exc.value.code) == 400
|
||||
assert exc.value.param == "model"
|
||||
assert "tool calling" in exc.value.message
|
||||
|
||||
def test_a_model_without_forced_tool_choice_support_remains_eligible(self, local_model_cost_map):
|
||||
supported_params = litellm.get_supported_openai_params(
|
||||
model="amazon.nova-pro-v1:0",
|
||||
custom_llm_provider="bedrock",
|
||||
)
|
||||
|
||||
assert supported_params is not None
|
||||
assert "tools" in supported_params
|
||||
assert "tool_choice" not in supported_params
|
||||
|
||||
|
||||
class TestSuggesterToleratesAModelThatRefusesItsSamplingParams:
|
||||
"""The model is operator-supplied, so it can be a reasoning model whose only accepted
|
||||
temperature is 1. This call pins temperature=0.2 for tool-selection determinism, which such
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue