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("--target_type function --target_name mymodule#function_name --probes encoding.InjectBase32".split())
- class Multiple(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/stable/garak/_config.py'>, **kwargs)Source
Bases:
SinglePass a function to call as a generator. The function must have the signature
function(prompt:str, generations:int, **kwargs)->List[Union(str, None)]and is specified in the formatmodule#functionwith the CLI or in the config file. The parameternameis reserved.- supports_multiple_generations = True
- class Single(name='', config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/stable/garak/_config.py'>, **kwargs)Source
Bases:
GeneratorPass a function to call as a generator. The function must have the signature
function(prompt:str, **kwargs)->List[Union(str, None)]and is specified in the formatmodule#functionwith the CLI or in the config file. The parameternameis reserved.Configurable parameters:
DEFAULT_PARAMScontents:kwargs={}
Default values are listed
See also Configuring garak for how to set these values.
Other attributes:
- doc_uri = 'https://github.com/NVIDIA/garak/issues/137'
- generator_family_name = 'function'
- supports_multiple_generations = False