πCustom scanners
[DRAFT: WORK IN PROGRESS]
Last updated
class BaseScanner(ABC):
def __init__(self, name: str = '') -> None:
self.name = name
@abstractmethod
def analyze(self, scan_obj: ScanModel, scan_id: UUID = uuid4()) -> ScanModel:
raise NotImplementedError('This method needs to be overridden in the subclass.')
def post_init(self):
""" Optional post-initialization method """
pass
from vigil.registry import Registration
@Registration.scanner(name='example', requires_config=False, requires_embedding=False, requires_vectordb=False)
class ExampleScanner(BaseScanner):
def __init__(self):
pass
[scanner:example]
threshold = 0.5@Registration.scanner(name='example', requires_config=True)
class ExampleScanner(BaseScanner):
""" Compare the cosine similarity of the prompt and response """
def __init__(self, threshold: float):
self.threshold = float(threshold)from typing import Callable
@Registration.scanner(name='example', requires_embedding=True)
class ExampleScanner(BaseScanner):
def __init__(self, embedder: Callable):
self.embedder = embedder
def analyze(self, scan_obj: ScanModel, scan_id: uuid.uuid4) -> ScanModel:
prompt_embedding = self.embedder.generate(scan_obj.prompt)