Skip to content

Commit

Permalink
generators: fix rasa issues #961 & #962 (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartin-tech committed Oct 30, 2024
2 parents 5922906 + 90794d5 commit ab13180
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ garak.*.jsonl
garak.log
hitlog.*.jsonl
.vscode
.history/
garak_runs/
runs/
logs/
2 changes: 2 additions & 0 deletions garak/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def _set_settings(config_obj, settings_obj: dict):


def _combine_into(d: dict, combined: dict) -> None:
if d is None:
return combined
for k, v in d.items():
if isinstance(v, dict):
_combine_into(v, combined.setdefault(k, nested_dict()))
Expand Down
1 change: 1 addition & 0 deletions garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def main(arguments=None) -> None:
for plugin_type in plugin_types:
opts_arg = f"{plugin_type}_options"
opts_file = f"{plugin_type}_option_file"
opts_cli_config = None
if opts_arg in args or opts_file in args:
if opts_arg in args:
opts_argv = getattr(args, opts_arg)
Expand Down
13 changes: 8 additions & 5 deletions garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ def _call_model(
}
resp = self.http_function(self.uri, **req_kArgs)
if resp.status_code in self.ratelimit_codes:
raise RateLimitHit(f"Rate limited: {resp.status_code} - {resp.reason}")
raise RateLimitHit(f"Rate limited: {resp.status_code} - {resp.reason}, uri: {self.uri}")

elif str(resp.status_code)[0] == "3":
raise NotImplementedError(
f"REST URI redirection: {resp.status_code} - {resp.reason}"
f"REST URI redirection: {resp.status_code} - {resp.reason}, uri: {self.uri}"
)

elif str(resp.status_code)[0] == "4":
raise ConnectionError(
f"REST URI client error: {resp.status_code} - {resp.reason}"
f"REST URI client error: {resp.status_code} - {resp.reason}, uri: {self.uri}"
)

elif str(resp.status_code)[0] == "5":
error_msg = f"REST URI server error: {resp.status_code} - {resp.reason}"
error_msg = f"REST URI server error: {resp.status_code} - {resp.reason}, uri: {self.uri}"
if self.retry_5xx:
raise IOError(error_msg)
else:
Expand All @@ -229,7 +229,10 @@ def _call_model(
len(self.response_json_field) > 0
), "response_json_field needs to be complete if response_json is true; ValueError should have been raised in constructor"
if self.response_json_field[0] != "$":
response = [response_object[self.response_json_field]]
if isinstance(response_object, list):
response = [item[self.response_json_field] for item in response_object]
else:
response = [response_object[self.response_json_field]]
else:
field_path_expr = jsonpath_ng.parse(self.response_json_field)
responses = field_path_expr.find(response_object)
Expand Down

0 comments on commit ab13180

Please sign in to comment.