Skip to content

Commit

Permalink
set requests UA in config
Browse files Browse the repository at this point in the history
  • Loading branch information
leondz committed Oct 28, 2024
1 parent 9d347f0 commit 68c8991
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 3 additions & 0 deletions garak/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 68c8991

Please sign in to comment.