From 90794d56c6dbda2935ca2ab9f9f83f0d22b623ce Mon Sep 17 00:00:00 2001 From: Greg Stephens Date: Sat, 26 Oct 2024 14:09:56 -0700 Subject: [PATCH] update for PR962 --- garak/data/__init__.py | 2 -- garak/generators/rest.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/garak/data/__init__.py b/garak/data/__init__.py index 606e03257..14d9ac0aa 100644 --- a/garak/data/__init__.py +++ b/garak/data/__init__.py @@ -40,7 +40,6 @@ def _determine_suffix(self): return self.relative_to(path) def _eval_paths(self, segment, next_call, relative): - print(f"segment: {segment}, relative: {relative}, next_call: {next_call}, search paths: {self.ORDERED_SEARCH_PATHS}") if self in self.ORDERED_SEARCH_PATHS and segment == relative: raise GarakException( f"The requested resource does not refer to a valid path" @@ -57,7 +56,6 @@ def _eval_paths(self, segment, next_call, relative): projected = (path / prefix_removed).parent else: current_path = path / prefix_removed - print(f"current_path: {current_path}") projected = getattr(current_path, next_call)(segment) if projected.exists(): return LocalDataPath(projected) diff --git a/garak/generators/rest.py b/garak/generators/rest.py index 746c8917f..17ebe9b11 100644 --- a/garak/generators/rest.py +++ b/garak/generators/rest.py @@ -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: @@ -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)