Bases: StandardGuardrail
Prompt injection detection encoder based model.
For more information, please see the model card:
Source code in src/any_guardrail/guardrails/sentinel/sentinel.py
| class Sentinel(StandardGuardrail):
"""Prompt injection detection encoder based model.
For more information, please see the model card:
- [Sentinel](https://huggingface.co/qualifire/prompt-injection-sentinel).
"""
SUPPORTED_MODELS: ClassVar = ["qualifire/prompt-injection-sentinel"]
def __init__(self, model_id: str | None = None, provider: StandardProvider | None = None) -> None:
"""Initialize the Sentinel guardrail."""
self.model_id = default(model_id, self.SUPPORTED_MODELS)
self.provider = provider or HuggingFaceProvider()
self.provider.load_model(self.model_id)
def _pre_processing(self, input_text: str) -> StandardPreprocessOutput:
return self.provider.pre_process(input_text)
def _inference(self, model_inputs: StandardPreprocessOutput) -> StandardInferenceOutput:
return self.provider.infer(model_inputs)
def _post_processing(self, model_outputs: StandardInferenceOutput) -> BinaryScoreOutput:
return match_injection_label(model_outputs, SENTINEL_INJECTION_LABEL, self.provider.model.config.id2label) # type: ignore[attr-defined]
|
__init__(model_id=None, provider=None)
Initialize the Sentinel guardrail.
Source code in src/any_guardrail/guardrails/sentinel/sentinel.py
| def __init__(self, model_id: str | None = None, provider: StandardProvider | None = None) -> None:
"""Initialize the Sentinel guardrail."""
self.model_id = default(model_id, self.SUPPORTED_MODELS)
self.provider = provider or HuggingFaceProvider()
self.provider.load_model(self.model_id)
|