Skip to content

Commit

Permalink
update for PR962
Browse files Browse the repository at this point in the history
  • Loading branch information
rgstephens committed Oct 26, 2024
1 parent 9fca398 commit 90794d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 0 additions & 2 deletions garak/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
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 90794d5

Please sign in to comment.