Develop a Custom Alerter
How to develop a custom alerter
The base abstraction for alerters is very basic, as it only defines two abstract methods that subclasses should implement:
post()
takes a string, posts it to the desired chat service, and returnsTrue
if the operation succeeded, elseFalse
.ask()
does the same aspost()
, but after sending the message, it waits until someone approves or rejects the operation from within the chat service (e.g., by sending "approve" / "reject" to the bot as response).ask()
then only returnsTrue
if the operation succeeded and was approved, elseFalse
.
Then base abstraction looks something like this:
class BaseAlerter(StackComponent, ABC):
"""Base class for all ZenML alerters."""
def post(
self, message: str, config: Optional[BaseAlerterStepConfig]
) -> bool:
"""Post a message to a chat service."""
return True
def ask(
self, question: str, config: Optional[BaseAlerterStepConfig]
) -> bool:
"""Post a message to a chat service and wait for approval."""
return True
This is a slimmed-down version of the base implementation. To see the full docstrings and imports, please check the source code on GitHub.
Creating your own custom alerter can be done in three steps:
- 1.Create a class that inherits from the
BaseAlerter
. - 2.Define the
FLAVOR
class variable in your class (e.g.,FLAVOR="discord"
) - 3.Implement the
post()
andask()
methods for your alerter.
Once you are done with the implementation, you can register it through the CLI as:
zenml alerter flavor register <THE-SOURCE-PATH-OF-YOUR-ALERTER>
Last modified 6mo ago