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

feature: amend garak user-agent #960

Merged
merged 14 commits into from
Nov 14, 2024
11 changes: 9 additions & 2 deletions garak/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

DICT_CONFIG_AFTER_LOAD = False

version = -1 # eh why this is here? hm. who references it
from garak import __version__

version = __version__
leondz marked this conversation as resolved.
Show resolved Hide resolved

system_params = (
"verbose narrow_output parallel_requests parallel_attempts skip_unknown".split()
Expand Down Expand Up @@ -144,12 +146,16 @@ def _load_yaml_config(settings_filenames) -> dict:


def _store_config(settings_files) -> None:
global system, run, plugins, reporting
global system, run, plugins, reporting, version
settings = _load_yaml_config(settings_files)
system = _set_settings(system, settings["system"])
run = _set_settings(run, settings["run"])
run.user_agent = run.user_agent.replace("{version}", version)
plugins = _set_settings(plugins, settings["plugins"])
reporting = _set_settings(reporting, settings["reporting"])
from requests import utils

utils.default_user_agent = run.user_agent
leondz marked this conversation as resolved.
Show resolved Hide resolved


def load_base_config() -> None:
Expand Down Expand Up @@ -193,6 +199,7 @@ def load_config(

logging.debug("Loading configs from: %s", ",".join(settings_files))
_store_config(settings_files=settings_files)

if DICT_CONFIG_AFTER_LOAD:
_lock_config_as_dict()
loaded = True
Expand Down
3 changes: 1 addition & 2 deletions garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ def main(arguments=None) -> None:
"""Main entry point for garak runs invoked from the CLI"""
import datetime

from garak import __version__, __description__
from garak import __description__
from garak import _config
from garak.exception import GarakException

_config.transient.starttime = datetime.datetime.now()
_config.transient.starttime_iso = _config.transient.starttime.isoformat()
_config.version = __version__

if arguments is None:
arguments = []
Expand Down
1 change: 1 addition & 0 deletions garak/resources/garak.core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ run:
eval_threshold: 0.5
generations: 5
probe_tags:
user_agent: "garak/{version} , LLM vulnerability scanner https://garak.ai"
leondz marked this conversation as resolved.
Show resolved Hide resolved

plugins:
model_type:
Expand Down
1 change: 1 addition & 0 deletions tests/generators/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@pytest.fixture
def set_rest_config():
_config.run.user_agent = "test user agent, garak.ai"
_config.plugins.generators["rest"] = {}
_config.plugins.generators["rest"]["RestGenerator"] = {
"name": DEFAULT_NAME,
Expand Down
Loading