Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting - 20240612 #733

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions garak/buffs/low_resource_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

""" Buff that converts prompts with different encodings. """

import logging
from collections.abc import Iterable
from deepl import Translator
from os import getenv

import garak.attempt
from garak import _config
Expand Down
5 changes: 4 additions & 1 deletion garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
command_options = "list_detectors list_probes list_generators list_buffs list_config plugin_info interactive report version".split()


def main(arguments=[]) -> None:
def main(arguments=None) -> None:
"""Main entry point for garak runs invoked from the CLI"""
import datetime

Expand All @@ -18,6 +18,9 @@ def main(arguments=[]) -> None:
_config.transient.starttime_iso = _config.transient.starttime.isoformat()
_config.version = __version__

if arguments is None:
arguments = []

import garak.command as command
import logging
import re
Expand Down
2 changes: 0 additions & 2 deletions garak/detectors/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
"""

import logging
import os
import sys

import backoff

from garak import _config
from garak.detectors import Detector
from garak.exception import APIKeyMissingError

perspective_classes = [
{
Expand Down
3 changes: 0 additions & 3 deletions garak/detectors/visual_jailbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

Detectors for guessing whether a jailbreak with both image and text prompt has been successful """

import garak.attempt
from garak import _config
from garak.detectors.base import StringDetector
from typing import List
import re


class FigStep(StringDetector):
Expand Down
1 change: 0 additions & 1 deletion garak/evaluators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import json
import logging
import os
from typing import List

from colorama import Fore, Style
Expand Down
2 changes: 0 additions & 2 deletions garak/generators/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"""

import logging
import os
from typing import List, Union

import backoff
import cohere
import tqdm

from garak import _config
from garak.exception import APIKeyMissingError
from garak.generators.base import Generator


Expand Down
1 change: 0 additions & 1 deletion garak/generators/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import logging
import re
import os
from typing import List, Union
import warnings

Expand Down
3 changes: 1 addition & 2 deletions garak/generators/nvcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import json
import logging
import os
import time
from typing import List, Union

import backoff
import requests

from garak import _config
from garak.exception import APIKeyMissingError, ModelNameMissingError
from garak.exception import ModelNameMissingError
from garak.generators.base import Generator


Expand Down
1 change: 0 additions & 1 deletion garak/generators/octo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""OctoML LLM interface"""


import os
from typing import List, Union

import backoff
Expand Down
2 changes: 0 additions & 2 deletions garak/generators/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* https://platform.openai.com/docs/model-index-for-researchers
"""

import os
import re
import logging
from typing import List, Union
Expand All @@ -19,7 +18,6 @@
import backoff

from garak import _config
from garak.exception import APIKeyMissingError
from garak.generators.base import Generator

# lists derived from https://platform.openai.com/docs/models
Expand Down
1 change: 0 additions & 1 deletion garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import json
import logging
import os
from typing import List, Union
import requests

Expand Down
5 changes: 4 additions & 1 deletion garak/harnesses/probewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _load_detector(self, detector_name: str) -> Detector:
logging.error(f" detector load failed: {detector_name}, skipping >>")
return False

def run(self, model, probenames, evaluator, buff_names=[]):
def run(self, model, probenames, evaluator, buff_names=None):
"""Execute a probe-by-probe scan

Probes are executed in name order. For each probe, the detectors
Expand All @@ -54,6 +54,9 @@ def run(self, model, probenames, evaluator, buff_names=[]):
:type buff_names: List[str]
"""

if buff_names is None:
buff_names = []

if not probenames:
msg = "No probes, nothing to do"
logging.warning(msg)
Expand Down
4 changes: 3 additions & 1 deletion garak/harnesses/pxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


class PxD(Harness):
def run(self, model, probe_names, detector_names, evaluator, buff_names=[]):
def run(self, model, probe_names, detector_names, evaluator, buff_names=None):
if buff_names is None:
buff_names = []
probe_names = sorted(probe_names)
detector_names = sorted(detector_names)
print(
Expand Down
1 change: 0 additions & 1 deletion garak/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# SPDX-License-Identifier: Apache-2.0

import argparse
import importlib
from logging import getLogger
import random
import sys
Expand Down
1 change: 1 addition & 0 deletions garak/probes/dan.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ class DanInTheWildMini(DanInTheWild):
Tries a set of 100 known jailbreaks, in an attempt to get a model to disregard
alignment/system prompt. Success is measured by not getting a safety mitigaton
message."""

active = True

def __init__(self, config_root=_config):
Expand Down
4 changes: 2 additions & 2 deletions garak/probes/goodside.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ class Tag(Probe):
primary_detector = "base.TriggerListDetector"
tags = [
"owasp:llm01",
"payload:generic"
"payload:generic",
"quality:Security:Adversarial",
"quality:Security:PromptStability",
]
]
goal = "inject invisible instructions"

prompts = []
Expand Down
1 change: 0 additions & 1 deletion garak/probes/leakreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import csv
import re
from typing import List

from garak.attempt import Attempt
from garak import _config
Expand Down
2 changes: 1 addition & 1 deletion garak/probes/malwaregen.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Payload(Probe):
tags = [
"avid-effect:security:S0403",
"quality:Behavioral:ContentSafety:LegalGoodsServices",
]
]
goal = "write a malware payload"

def __init__(self, config_root=_config):
Expand Down
10 changes: 9 additions & 1 deletion garak/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ class Report:
"""

def __init__(
self, report_location, records=[], metadata=None, evaluations=None, scores=None
self,
report_location,
records=None,
metadata=None,
evaluations=None,
scores=None,
):
self.report_location = report_location
self.records = records
self.metadata = metadata
self.evaluations = evaluations
self.scores = scores

if self.records is None:
self.records = []

def load(self):
"""
Loads a garak report.
Expand Down
Loading