mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix(guardrails): remove unused TrendAI logging scan scope
This commit is contained in:
parent
d011f18d65
commit
b6e4e45a39
4 changed files with 4 additions and 27 deletions
|
|
@ -31,7 +31,6 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"
|
|||
timeout=settings.timeout,
|
||||
stream_overlap_size=settings.stream_overlap_size,
|
||||
response_content_chunk_size_bytes=settings.response_content_chunk_size_bytes,
|
||||
logging_only_scan=settings.logging_only_scan,
|
||||
guardrail_name=guardrail_name,
|
||||
event_hook=_normalize_event_hook(litellm_params.mode),
|
||||
default_on=litellm_params.default_on is True,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ class TrendAISettings(BaseModel):
|
|||
timeout: float = 5.0
|
||||
stream_overlap_size: int = 256
|
||||
response_content_chunk_size_bytes: int = 49_500
|
||||
logging_only_scan: Literal["request", "response", "both"] = "both"
|
||||
|
||||
|
||||
class TrendAIChatMessage(BaseModel):
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ class TrendAIGuardrail(CustomGuardrail):
|
|||
timeout: float = 5.0,
|
||||
stream_overlap_size: int = 256,
|
||||
response_content_chunk_size_bytes: int = RESPONSE_CONTENT_CHUNK_SIZE_BYTES,
|
||||
logging_only_scan: Literal["request", "response", "both"] = "both",
|
||||
async_handler: _AsyncHTTPClient | None = None,
|
||||
guardrail_name: str | None = None,
|
||||
event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | Mode | None = None,
|
||||
|
|
@ -100,8 +99,6 @@ class TrendAIGuardrail(CustomGuardrail):
|
|||
)
|
||||
if fallback_on_error not in ("block", "allow"):
|
||||
raise ValueError("fallback_on_error must be 'block' or 'allow'")
|
||||
if logging_only_scan not in ("request", "response", "both"):
|
||||
raise ValueError("logging_only_scan must be 'request', 'response', or 'both'")
|
||||
if timeout <= 0:
|
||||
raise ValueError("timeout must be greater than zero")
|
||||
if stream_overlap_size < 0:
|
||||
|
|
@ -116,7 +113,6 @@ class TrendAIGuardrail(CustomGuardrail):
|
|||
self.timeout: float = timeout
|
||||
self.stream_overlap_size: int = stream_overlap_size
|
||||
self.response_content_chunk_size_bytes: int = response_content_chunk_size_bytes
|
||||
self.logging_only_scan: Literal["request", "response", "both"] = logging_only_scan
|
||||
self.async_handler: _AsyncHTTPClient = async_handler or get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.GuardrailCallback
|
||||
)
|
||||
|
|
@ -137,9 +133,6 @@ class TrendAIGuardrail(CustomGuardrail):
|
|||
GuardrailEventHooks.logging_only,
|
||||
]
|
||||
|
||||
def logging_only_scan_scope(self) -> Literal["request", "response", "both"]:
|
||||
return self.logging_only_scan
|
||||
|
||||
@log_guardrail_information
|
||||
async def apply_guardrail(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ def _guardrail(
|
|||
timeout: float = 5.0,
|
||||
stream_overlap_size: int = 256,
|
||||
response_content_chunk_size_bytes: int = 49_500,
|
||||
logging_only_scan: Literal["request", "response", "both"] = "both",
|
||||
async_handler: httpx.AsyncClient | None = None,
|
||||
api_base: str = "https://guard.example.com/v3.0/aiSecurity",
|
||||
event_hook: GuardrailEventHooks = GuardrailEventHooks.pre_call,
|
||||
|
|
@ -50,7 +49,6 @@ def _guardrail(
|
|||
timeout=timeout,
|
||||
stream_overlap_size=stream_overlap_size,
|
||||
response_content_chunk_size_bytes=response_content_chunk_size_bytes,
|
||||
logging_only_scan=logging_only_scan,
|
||||
async_handler=async_handler,
|
||||
guardrail_name="trendai",
|
||||
event_hook=event_hook,
|
||||
|
|
@ -538,29 +536,17 @@ def _logged_call(user_text: str, assistant_text: str) -> tuple[dict[str, object]
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("scope", "expected_scans"),
|
||||
[
|
||||
("request", ["user a@b.com"]),
|
||||
("response", ["assistant SECRET"]),
|
||||
("both", ["user a@b.com", "assistant SECRET"]),
|
||||
],
|
||||
)
|
||||
async def test_logging_only_scan_scope_selects_which_side_is_scanned(
|
||||
scope: Literal["request", "response", "both"], expected_scans: Sequence[str]
|
||||
) -> None:
|
||||
async def test_logging_only_scans_both_sides_without_modifying_them() -> None:
|
||||
respond, scanned = _engine(redact={"a@b.com": "[EMAIL]", "SECRET": "******"})
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(respond)) as client:
|
||||
guardrail = _guardrail(
|
||||
async_handler=client, logging_only_scan=scope, event_hook=GuardrailEventHooks.logging_only
|
||||
)
|
||||
guardrail = _guardrail(async_handler=client, event_hook=GuardrailEventHooks.logging_only)
|
||||
kwargs, response = _logged_call("user a@b.com", "assistant SECRET")
|
||||
out_kwargs, out_response = await guardrail.async_logging_hook(kwargs, response, CallTypes.acompletion.value)
|
||||
|
||||
assert scanned == list(expected_scans)
|
||||
assert scanned == ["user a@b.com", "assistant SECRET"]
|
||||
assert out_kwargs["messages"] == [{"role": "user", "content": "user a@b.com"}]
|
||||
assert out_response is response
|
||||
assert response.choices[0].message.content == "assistant SECRET"
|
||||
entries = out_kwargs["standard_logging_object"]["guardrail_information"]
|
||||
assert [entry["guardrail_status"] for entry in entries] == ["success"] * len(expected_scans)
|
||||
assert [entry["guardrail_status"] for entry in entries] == ["success", "success"]
|
||||
assert all(entry["guardrail_mode"] == "logging_only" for entry in entries)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue