Skip to content
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
12 changes: 6 additions & 6 deletions garak/analyze/misp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@


def misp_report(include_untagged: bool = True) -> None:
misp_resource_file = data_path / "misp_descriptions.tsv"
misp_descriptions = {}
misp_resource_file = data_path / "tags.misp.tsv"
tag_descriptions = {}
if os.path.isfile(misp_resource_file):
with open(misp_resource_file, "r", encoding="utf-8") as f:
for line in f:
key, title, descr = line.strip().split("\t")
misp_descriptions[key] = (title, descr)
tag_descriptions[key] = (title, descr)

probes_per_tag = defaultdict(list)

Expand All @@ -46,11 +46,11 @@ def misp_report(include_untagged: bool = True) -> None:
if tags == [] and include_untagged:
print(f"{plugin_name}: no tags defined")
for tag in tags:
if tag not in misp_descriptions:
print(f"{plugin_name}: tag {tag} undefined in misp_descriptions.tsv")
if tag not in tag_descriptions:
print(f"{plugin_name}: tag {tag} undefined in garak/data/tags.misp.tsv")
probes_per_tag[tag].append(plugin_name)

for misp_tag in misp_descriptions.keys():
for misp_tag in tag_descriptions.keys():
if len(probes_per_tag[misp_tag]) == 0:
print(f"{misp_tag}: zero probes testing this")
else:
Expand Down
10 changes: 5 additions & 5 deletions garak/analyze/report_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
about_z_template = templateEnv.get_template("digest_about_z.jinja")


misp_resource_file = data_path / "misp_descriptions.tsv"
misp_descriptions = {}
misp_resource_file = data_path / "tags.misp.tsv"
tag_descriptions = {}
if os.path.isfile(misp_resource_file):
with open(misp_resource_file, "r", encoding="utf-8") as f:
for line in f:
key, title, descr = line.strip().split("\t")
misp_descriptions[key] = (title, descr)
tag_descriptions[key] = (title, descr)


def map_absolute_score(score: float) -> int:
Expand Down Expand Up @@ -239,8 +239,8 @@ def _get_group_info(probe_group, group_score, taxonomy, config=_config) -> dict:
)
elif probe_group != "other":
probe_group_name = f"{taxonomy}:{probe_group}"
if probe_group_name in misp_descriptions:
probe_group_name, group_doc = misp_descriptions[probe_group_name]
if probe_group_name in tag_descriptions:
probe_group_name, group_doc = tag_descriptions[probe_group_name]
else:
probe_group_name = "Uncategorized"

Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions tests/probes/test_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from garak import _config, _plugins
import garak.probes

PROBES = [classname for (classname, active) in _plugins.enumerate_plugins("probes")]

DETECTORS = [
Expand All @@ -20,7 +21,7 @@


with open(
_config.transient.package_dir / "data" / "misp_descriptions.tsv",
_config.transient.package_dir / "data" / "tags.misp.tsv",
"r",
encoding="utf-8",
) as misp_data:
Expand Down Expand Up @@ -74,7 +75,9 @@ def test_probe_metadata(classname):
p = _plugins.load_plugin(classname)
assert isinstance(p.goal, str), "probe goals should be a text string"
assert len(p.goal) > 0, "probes must state their general goal"
assert p.lang is not None and (p.lang == "*" or langcodes.tag_is_valid(p.lang)), "lang must be either * or a BCP47 code"
assert p.lang is not None and (
p.lang == "*" or langcodes.tag_is_valid(p.lang)
), "lang must be either * or a BCP47 code"
assert isinstance(
p.doc_uri, str
), "probes should give a doc uri describing/citing the attack"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_allow_relative_in_path():


def test_known_resource_found():
known_filename = "misp_descriptions.tsv"
known_filename = "tags.misp.tsv"
source = data_path / known_filename
assert source.name == known_filename

Expand Down
Loading