Skip to content

Commit

Permalink
restore req_template_json_object lost in refactor (#729)
Browse files Browse the repository at this point in the history
* restore `req_template_json_object` lost in refactor

Signed-off-by: Jeffrey Martin <[email protected]>

* fix doc json example

Signed-off-by: Jeffrey Martin <[email protected]>

* expect _supported_params as a tuple

`tuple` is more strict and better suited, list was also not used

Signed-off-by: Jeffrey Martin <[email protected]>

---------

Signed-off-by: Jeffrey Martin <[email protected]>
  • Loading branch information
jmartin-tech authored Jun 6, 2024
1 parent 3833eef commit 403e67f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion garak/configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _apply_config(self, config):
# should this be coupled to `_plugins`?
continue
if (
isinstance(self._supported_params, list)
isinstance(self._supported_params, tuple)
and k not in self._supported_params
):
# if the class has a set of supported params skip unknown params
Expand Down
31 changes: 16 additions & 15 deletions garak/generators/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ class RestGenerator(Generator):
and response value are both under the ``text`` key, we'd define the service
using something like: ::
{"rest"
{
"rest": {
"RestGenerator": {
{
"name": "example service",
"uri": "https://example.ai/llm",
"method": "post",
"headers":{
"X-Authorization": "$KEY",
},
"req_template_json_object":{
"text":"$INPUT"
},
"response_json": true,
"response_json_field": "text"
}
"name": "example service",
"uri": "https://example.ai/llm",
"method": "post",
"headers": {
"X-Authorization": "$KEY",
},
"req_template_json_object": {
"text": "$INPUT"
},
"response_json": true,
"response_json_field": "text"
}
}
}
NB. ``response_json_field`` can also be a JSONPath, for JSON responses where
the target text is not in a top level field. It is treated as a JSONPath
Expand Down Expand Up @@ -130,6 +130,7 @@ class RestGenerator(Generator):
"headers",
"response_json",
"response_json_field",
"req_template_json_object",
"request_timeout",
"ratelimit_codes",
"temperature",
Expand All @@ -153,7 +154,7 @@ def __init__(self, uri=None, generations=10, config_root=_config):
hasattr(self, "req_template_json_object")
and self.req_template_json_object is not None
):
self.req_template = json.dumps(self.req_template_object)
self.req_template = json.dumps(self.req_template_json_object)

if self.response_json:
if self.response_json_field is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_config_supported_params(generator_sub_config):
class mock_supported(mockConfigurable):
__module__ = "garak.generators.mock"

_supported_params = ["constructor_param", "defaulted_constructor_param"]
_supported_params = ("constructor_param", "defaulted_constructor_param")

m = mock_supported(config_root=generator_sub_config)
for k, v in generator_sub_config.generators["mock"].items():
Expand Down

0 comments on commit 403e67f

Please sign in to comment.