Adding a New Method to DetoxAI
In this tutorial, we will show you how to add a new method to DetoxAI.
Files to edit:
methods/your_method.pymethods/__init__.pycore/interface.py
methods/your_method.py:
- Implement your new method:
Inherit from
ModelCorrectionMethodImplement the abstract
apply_model_correctionmethod, make sure it has**kwargsin the constructor to facilitate flushing unused arguments (yes, we know this is not the best practice, but it is a compromise we made to make the API more flexible)
Note
Technically, this is all you need to do, but we recommend checking out already implemented methods to see how they are structured and what ideas and workarounds we used to introduce hooks, logging, and all that fancy stuff.
methods/__init__.py:
Import your new method to make it visible in the package.
core/interface.py:
Import your new method at the top to make it available in the interface script.
Add to
_method_mappingdictionary. This maps the method name to the class name.Add an entry in
DEFAULT_METHODS_CONFIGand set a default config to your method, if applicable. There has to be an entry, but it can be empty if your method does not have any default config.