mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(guardrails): use PEP 604/585 type hints in pattern prefilter code
Signed-off-by: Jacinta Ferrant <jacinta.ferrant@gmail.com>
This commit is contained in:
parent
6bba4ba27e
commit
93b8940082
2 changed files with 7 additions and 7 deletions
|
|
@ -175,7 +175,7 @@ class ContentFilterGuardrail(CustomGuardrail):
|
|||
llm_router: Optional[Router] = None,
|
||||
image_model: Optional[str] = None,
|
||||
competitor_intent_config: Optional[Dict[str, Any]] = None,
|
||||
pattern_prefilter: Optional[PatternPrefilter] = None,
|
||||
pattern_prefilter: PatternPrefilter | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
|
|
@ -791,8 +791,8 @@ class ContentFilterGuardrail(CustomGuardrail):
|
|||
raise
|
||||
|
||||
def _build_pattern_prefilter(
|
||||
self, injected_prefilter: Optional[PatternPrefilter]
|
||||
) -> Tuple[PatternPrefilter, Tuple[Dict[str, Any], ...]]:
|
||||
self, injected_prefilter: PatternPrefilter | None
|
||||
) -> tuple[PatternPrefilter, tuple[dict[str, Any], ...]]:
|
||||
"""
|
||||
Partition compiled_patterns into ones a fast pre-filter can rule out
|
||||
and ones that must always run (contextual keyword-proximity patterns,
|
||||
|
|
@ -805,7 +805,7 @@ class ContentFilterGuardrail(CustomGuardrail):
|
|||
proven cannot match. It never changes what gets matched or masked.
|
||||
"""
|
||||
|
||||
def is_contextual(p: Dict[str, Any]) -> bool:
|
||||
def is_contextual(p: dict[str, Any]) -> bool:
|
||||
return p["keyword_regex"] is not None or p["allow_word_numbers"]
|
||||
|
||||
if injected_prefilter is not None:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ semantics for patterns that might.
|
|||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import FrozenSet, List, Protocol, Tuple
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class PatternPrefilter(Protocol):
|
||||
|
|
@ -22,8 +22,8 @@ class AlwaysMatchPrefilter:
|
|||
|
||||
|
||||
def build_rust_pattern_prefilter(
|
||||
pattern_sources: List[str],
|
||||
) -> Tuple[PatternPrefilter, FrozenSet[int]]:
|
||||
pattern_sources: list[str],
|
||||
) -> tuple[PatternPrefilter, frozenset[int]]:
|
||||
"""
|
||||
Build a Rust-backed prefilter for `pattern_sources`.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue