plugins
garak._plugins
This module manages plugin enumeration and loading.
There is one class per plugin in garak.
Enumerating the classes, with e.g. --list_probes on the command line, means importing each module.
Therefore, modules should do as little as possible on load, and delay
intensive activities (like loading classifiers) until a plugin’s class is instantiated.
Code
Functions for working with garak plugins (enumeration, loading, etc)
- class PluginEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)Source
Bases:
JSONEncoder- default(obj)Source
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
- class PluginProviderSource
Bases:
objectCentral registry of plugin instances
Newly requested plugins are first checked against this Provider for duplication.
- enumerate_plugins(category: str = 'probes', skip_base_classes=True) List[tuple[str, bool]]Source
A function for listing all modules & plugins of the specified kind.
garak’s plugins are organised into four packages - probes, detectors, generators and harnesses. Each package contains a base module defining the core plugin classes. The other modules in the package define classes that inherit from the base module’s classes.
enumerate_plugins() works by first looking at the base module in a package and finding the root classes here; it will then go through the other modules in the package and see which classes can be enumerated from these.
- Parameters:
category (str) – the name of the plugin package to be scanned; should be one of probes, detectors, generators, or harnesses.
- load_plugin(path, break_on_fail=True, config_root=<module 'garak._config' from '/home/docs/checkouts/readthedocs.org/user_builds/garak/checkouts/latest/docs/source/../../garak/_config.py'>) objectSource
load_plugin takes a path to a plugin class, and attempts to load that class. If successful, it returns an instance of that class.