diff --git a/src/giskard_hub/data/scan.py b/src/giskard_hub/data/scan.py index de833eb4..53193f9d 100644 --- a/src/giskard_hub/data/scan.py +++ b/src/giskard_hub/data/scan.py @@ -21,72 +21,6 @@ class ScanCategory(BaseData): owasp_id: Optional[str] = field(default=None) -SCAN_CATEGORIES = [ - ScanCategory( - id="gsk:threat-type='prompt-injection'", - title="Prompt Injection", - description="Attempts to manipulate model behavior through crafted inputs", - owasp_id="OWASP LLM01", - ), - ScanCategory( - id="gsk:threat-type='data-privacy-exfiltration'", - title="Data Privacy & Exfiltration", - description="Unauthorized exposure of sensitive or private information", - owasp_id="OWASP LLM05", - ), - ScanCategory( - id="gsk:threat-type='harmful-content-generation'", - title="Harmful Content Generation", - description="Generation of harmful, offensive, or inappropriate content", - ), - ScanCategory( - id="gsk:threat-type='excessive-agency'", - title="Excessive Agency", - description="Model given too much autonomy or permissions beyond intended scope", - owasp_id="OWASP LLM06", - ), - ScanCategory( - id="gsk:threat-type='internal-information-exposure'", - title="Internal Information Exposure", - description="Exposure of internal system information or model architecture", - owasp_id="OWASP LLM01-07", - ), - ScanCategory( - id="gsk:threat-type='training-data-extraction'", - title="Training Data Extraction", - description="Attempts to extract training data from the model", - owasp_id="OWASP LLM02", - ), - ScanCategory( - id="gsk:threat-type='denial-of-service'", - title="Denial of Service", - description="Resource exhaustion attacks against the model or system", - owasp_id="OWASP LLM10", - ), - ScanCategory( - id="gsk:threat-type='hallucination'", - title="Hallucination / Misinformation", - description="Generation of false or misleading information presented as fact", - owasp_id="OWASP LLM08", - ), - ScanCategory( - id="gsk:threat-type='misguidance-and-unauthorized-advice'", - title="Misguidance & Unauthorized Advice", - description="Providing inappropriate guidance or advice outside intended scope", - ), - ScanCategory( - id="gsk:threat-type='legal-and-financial-risk'", - title="Legal & Financial Risk", - description="Responses that could create legal or financial liability", - ), - ScanCategory( - id="gsk:threat-type='brand-damaging-and-reputation'", - title="Brand Damaging & Reputation", - description="Responses that could damage brand reputation or public trust", - ), -] - - class ScanGrade(str, Enum): A = "A" B = "B" @@ -279,7 +213,9 @@ def print_metrics(self): title=f"Scan Result [bold cyan]{self.id}[/bold cyan]", ) - category_map = {cat.id: cat.title for cat in SCAN_CATEGORIES} + category_map = { + cat.id: cat.title for cat in self._client.scans.list_categories() + } probe_results = self.results probe_data = [] diff --git a/src/giskard_hub/resources/scans.py b/src/giskard_hub/resources/scans.py index 33010733..85787de7 100644 --- a/src/giskard_hub/resources/scans.py +++ b/src/giskard_hub/resources/scans.py @@ -1,8 +1,8 @@ +from functools import lru_cache from typing import List, Optional from ..data._base import NOT_GIVEN, filter_not_given from ..data.scan import ( - SCAN_CATEGORIES, ProbeAttempt, ProbeResult, ScanCategory, @@ -15,6 +15,7 @@ class ScansResource(APIResource): + @lru_cache(maxsize=1) def list_categories(self) -> List[ScanCategory]: """List scan categories that can be use as tags to create/launch a scan. @@ -22,7 +23,8 @@ def list_categories(self) -> List[ScanCategory]: ------- List[ScanCategory]: A list of `ScanCategory` objects representing all available scan categories. """ - return SCAN_CATEGORIES + data = self._client.get(f"{_SCAN_BASE_URL}/categories") + return [ScanCategory.from_dict(item) for item in data["items"]] def create( self, @@ -47,8 +49,6 @@ def create( ScanResult The created scan result. """ - if not tags or len(tags) == 0: - tags = [category.id for category in self.list_categories()] data = filter_not_given( {