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

Conf #332

Merged
merged 37 commits into from
Nov 28, 2023
Merged

Conf #332

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d9eb961
start integrating settings by config file
leondz Nov 21, 2023
4f6ffca
tests pass (coverage isn't high enough yet)
leondz Nov 21, 2023
e15bace
add basic docs re: config loading
leondz Nov 22, 2023
b5175bd
have code access new locations withing _config; stop accessing garak.…
leondz Nov 22, 2023
6d1eb11
clear up references to _config.transient.reportfile
leondz Nov 22, 2023
e12410b
cli_args now stores params directly specified on CLI only (plus comma…
leondz Nov 22, 2023
9f69919
search for plugin spec in config, not in args
leondz Nov 22, 2023
dd24c16
amend reporting write call
leondz Nov 22, 2023
6b66352
plugin planning now uses spec & spec parsing
leondz Nov 22, 2023
28cdc26
uuid only generated once
leondz Nov 22, 2023
8bd376d
configure logging before it's used in _config
leondz Nov 24, 2023
2e04447
re-enable CLI short form options & CLI param typing
leondz Nov 24, 2023
0509354
reinstate unit on completion timer
leondz Nov 24, 2023
5337cf8
add list_config command; avoid configs getting all merged into one su…
leondz Nov 24, 2023
cb2d376
moved model_name, model_type to _config.plugins
leondz Nov 24, 2023
0d249a8
track config param name locations in _config.py
leondz Nov 24, 2023
29d29e3
add config testing, include CLI option tests
leondz Nov 24, 2023
800348c
implement config file priority; remove dynaconf (doesn't support hier…
leondz Nov 24, 2023
edeacf0
runs can be launched from config file alone
leondz Nov 24, 2023
e6fd8ec
support loading generator, probe options from yaml
leondz Nov 27, 2023
3cabdc9
add stub failing tests for config
leondz Nov 27, 2023
f4e7125
reconfig and test probe, generator CLI cfg file loading & structure
leondz Nov 28, 2023
af2c5ca
clean up cli param setting
leondz Nov 28, 2023
60c2a15
set up plugin config-on-load; start removing generator/plugin_options…
leondz Nov 28, 2023
b3a31bb
add probespec parsing tests
leondz Nov 28, 2023
13126f5
test generator parameter cli loading
leondz Nov 28, 2023
7de5a60
test generator config loading
leondz Nov 28, 2023
8c16fd8
check that cli probe options override yaml
leondz Nov 28, 2023
9e7b9ab
check that cli probe options override yaml
leondz Nov 28, 2023
99a0945
check that cli probe options override yaml
leondz Nov 28, 2023
602fa3b
check CLI generations param overrides run param
leondz Nov 28, 2023
fd3f753
test that site cfg overrides core cfg
leondz Nov 28, 2023
a7ab496
config tests passing
leondz Nov 28, 2023
3e73bc7
encoding probe uses new conf structure
leondz Nov 28, 2023
ddad752
update rest plugin to use standard config points
leondz Nov 28, 2023
c1913cb
tidy config printing
leondz Nov 28, 2023
478539a
Merge branch 'main' into conf
leondz Nov 28, 2023
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
18 changes: 5 additions & 13 deletions garak/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def print_buffs():
def plugin_info(plugin_name):
import inspect

from garak._plugins import enumerate_plugins, load_plugin
from garak._plugins import load_plugin

# load plugin
try:
plugin = load_plugin(plugin_name)
print(f"Info on {plugin_name}:")
print(f"Configured info on {plugin_name}:")
priority_fields = ["description"]
skip_fields = ["prompts", "triggers"]
# print the attribs it has
Expand Down Expand Up @@ -195,14 +195,6 @@ def list_config():
print("_config:")
_enumerate_obj_values(_config)

print("system:")
_enumerate_obj_values(_config.system)

print("transient:")
_enumerate_obj_values(_config.transient)

print("run:")
_enumerate_obj_values(_config.run)

print("plugins:")
_enumerate_obj_values(_config.plugins)
for section in "system transient run plugins".split():
print(f"{section}:")
_enumerate_obj_values(getattr(_config, section))
42 changes: 22 additions & 20 deletions garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RESTRateLimitError(Exception):
class RestGenerator(Generator):
"""Generic API interface for REST models

Uses the following options from _config.run.generator_options:
Uses the following options from _config.run.generators["rest"]:
* uri - (optional) the URI of the REST endpoint; this can also be passed
in --model_name
* name - a short name for this service; defaults to the uri
Expand Down Expand Up @@ -63,18 +63,20 @@ class RestGenerator(Generator):
and response value are both under the "text" key, we'd define the service
using something like:

{
"name": "example service",
"uri": "https://example.ai/llm",
"method": "post",
"headers":{
"X-Authorization": "$KEY",
},
"req_template_json_object":{
"text":"$INPUT"
},
"response_json": true,
"response_json_field": "text"
{"rest.RestGenerator":
{
"name": "example service",
"uri": "https://example.ai/llm",
"method": "post",
"headers":{
"X-Authorization": "$KEY",
},
"req_template_json_object":{
"text":"$INPUT"
},
"response_json": true,
"response_json_field": "text"
}
}

To use this specification with garak, you can either pass the JSON as a
Expand Down Expand Up @@ -110,7 +112,7 @@ def __init__(self, uri=None, generations=10):
self.retry_5xx = True
self.key_env_var = "REST_API_KEY"

if "generator_options" in dir(_config.plugins):
if "rest" in dir(_config.plugins.generators):
for field in (
"name",
"uri",
Expand All @@ -122,19 +124,19 @@ def __init__(self, uri=None, generations=10):
"response_timeout",
"ratelimit_codes",
):
if field in _config.plugins.generator_options:
setattr(self, field, _config.plugins.generator_options[field])
if field in _config.plugins.generators["rest"]:
setattr(self, field, _config.plugins.generator["rest"][field])

if "req_template_json_object" in _config.plugins.generator_options:
if "req_template_json_object" in _config.plugins.generators["rest"]:
self.req_template = json.dumps(
_config.plugins.generator_options["req_template_json_object"]
_config.plugins.generators["rest"]["req_template_json_object"]
)

if (
self.response_json
and "response_json_field" in _config.plugins.generator_options
and "response_json_field" in _config.plugins.generators["rest"]
):
self.response_json_field = _config.plugins.generator_options[
self.response_json_field = _config.plugins.generators["rest"][
"response_json_field"
]

Expand Down
10 changes: 5 additions & 5 deletions garak/probes/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def load_payloads():
payloads = []

if _config.plugins.probe_options:
if "encoding.payloads" in _config.plugins.probe_options:
if isinstance(_config.plugins.probe_options["encoding.payloads"], str):
_config.plugins.probe_options["encoding.payloads"] = [
_config.plugins.probe_options["encoding.payloads"]
if "encoding" in _config.plugins.probes:
if isinstance(_config.plugins.probes["encoding"]["payloads"], str):
_config.plugins.probes["encoding"]["payloads"] = [
_config.plugins.probes["encoding"]["payloads"]
]
for payload_class in _config.plugins.probe_options["encoding.payloads"]:
for payload_class in _config.plugins.probes["encoding"]["payloads"]:
if payload_class in payload_library:
payloads += payload_library[payload_class]

Expand Down
Loading