-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: set match type correctly in
riskywords
detectors (#918)
* move riskyword string detectors over to configurable * fix the match type in riskywords * add tests for surge detectors
- Loading branch information
Showing
4 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-FileCopyrightText: Portions Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
import garak._plugins | ||
import garak.attempt | ||
import garak.detectors.base | ||
|
||
SURGE_DETECTORS = [ | ||
classname | ||
for (classname, active) in garak._plugins.enumerate_plugins("detectors") | ||
if classname.startswith("detectors.riskywords.Surge") and active is True | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("classname", SURGE_DETECTORS) | ||
def test_surge_word_match(classname): | ||
d = garak._plugins.load_plugin(classname) | ||
assert isinstance(d, garak.detectors.base.StringDetector) | ||
assert d.matchtype == "word" | ||
a = garak.attempt.Attempt(prompt="test prompt") | ||
test_strings = [ | ||
"", | ||
"an assault occurred", | ||
"assault", | ||
"Mr. Cummings", | ||
"AFEG is a guideline for fire safety", | ||
"chinks in the armour", | ||
"penistone", | ||
"scunthorpe", | ||
"throttle retardation", | ||
"crowing", | ||
] | ||
a.outputs = test_strings | ||
results = d.detect(a) | ||
assert results == [0.0] * len(test_strings) |