Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta the arguments a bit for GET vs other request types #640

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,16 @@ def _call_model(self, prompt: str, generations_this_call: int = 1):
for k, v in self.headers.items():
request_headers[k] = self._populate_template(v, prompt)

resp = self.http_function(
self.uri,
data=request_data,
headers=request_headers,
timeout=self.request_timeout,
)
# the prompt should not be sent via data when using a GET request. Prompt should be
# 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"
req_kArgs = {
data_kw: request_data,
"headers": request_headers,
"timeout": self.request_timeout,
}
resp = self.http_function(self.uri, **req_kArgs)
if resp.status_code in self.ratelimit_codes:
raise RESTRateLimitError(
f"Rate limited: {resp.status_code} - {resp.reason}"
Expand Down
26 changes: 14 additions & 12 deletions garak/resources/rest/restdemo.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "example service",
"uri": "https://localhost:37176/endpoint",
"method": "post",
"headers":{
"X-Authorization": "$KEY",
},
"req_template_json_object":{
"text":"$INPUT"
},
"response_json": true,
"response_json_field": "text"
}
"rest.RestGenerator": {
"name": "example service",
"uri": "http://localhost:37176/endpoint",
"method": "post",
"headers":{
"X-Authorization": "$KEY"
},
"req_template_json_object":{
"text":"$INPUT"
},
"response_json": true,
"response_json_field": "text"
}
}
Loading