garak.generators.function

function-based generator

Call a given function to use as a generator; specify this as either the model name on the command line, or as the parameter to the constructor.

This generator is designed to be used programmatically, rather than invoked from the CLI. An example usage might be:

``` import mymodule import garak.generators.function

g = garak.generators.function.Single(name=”mymodule#myfunction”) ```

The target function is expected to take a string, and return a string. Other arguments passed by garak are forwarded to the target function.

Note that one can import the intended target module into scope and then invoke a garak run via garak’s cli module, using something like:

``` import garak import garak.cli import mymodule

garak.cli.main(”–model_type function –model_name mymodule#function_name –probes encoding.InjectBase32”.split()) ```

class garak.generators.function.Multiple(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/docs/source/../../garak/_config.py'>, **kwargs)

Bases: Single

pass a module#function to be called as generator, with format function(prompt:str, generations:int, **kwargs)->List[Union(str, None)]

supports_multiple_generations = True
class garak.generators.function.Single(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/docs/source/../../garak/_config.py'>, **kwargs)

Bases: Generator

pass a module#function to be called as generator, with format function(prompt:str, **kwargs)->List[Union(str, None)] the parameter name is reserved

DEFAULT_PARAMS = {'kwargs': {}}
doc_uri = 'https://github.com/leondz/garak/issues/137'
generator_family_name = 'function'
supports_multiple_generations = False