From 68c8991f3b96db04d4c15539fc71b8cae62649ea Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Mon, 28 Oct 2024 17:42:53 +0100 Subject: [PATCH] set requests UA in config --- garak/_config.py | 3 +++ garak/generators/rest.py | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/garak/_config.py b/garak/_config.py index 72004b016..b232e5c8c 100644 --- a/garak/_config.py +++ b/garak/_config.py @@ -153,6 +153,9 @@ def _store_config(settings_files) -> None: 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 def load_base_config() -> None: diff --git a/garak/generators/rest.py b/garak/generators/rest.py index 500dae47c..746c8917f 100644 --- a/garak/generators/rest.py +++ b/garak/generators/rest.py @@ -67,7 +67,6 @@ def __init__(self, uri=None, config_root=_config): self.escape_function = self._json_escape self.retry_5xx = True self.key_env_var = self.ENV_VAR if hasattr(self, "ENV_VAR") else None - self.user_agent = _config.run.user_agent # load configuration since super.__init__ has not been called self._load_config(config_root) @@ -188,8 +187,6 @@ def _call_model( # serialized as parameters, in general a method could be created to add # the prompt data to a request via params or data based on the action verb data_kw = "params" if self.http_function == requests.get else "data" - if "User-Agent" not in request_headers: - request_headers["User-Agent"] = self.user_agent req_kArgs = { data_kw: request_data, "headers": request_headers,