ow the recommendations from the Project templates.In steps/alerts/notify_on.py, you will find a step to notify the user about success and a function used to notify the user about step failure using the Alerter from the active stack.

We use @step for success notification to only notify the user about a fully successful pipeline run and not about every successful step.

Inside this code file, you can find how developers can work with Al component to send notification messages across configured channels:

from zenml.client import Client

from zenml import get_step_context

alerter = Client().active_stack.alerter

def notify_on_failure() -> None:

"""Notifies user on step failure. Used in Hook."""

step_context = get_step_context()

if alerter and step_context.pipeline_run.config.extra["notify_on_failure"]:

alerter.post(message=build_message(status="failed"))

If the Al component is not present in Stack we suppress notification, but you can also dump it to the log as Error using:

from zenml.client import Client

from zenml.logger import get_logger

from zenml import get_step_context

logger = get_logger(__name__)

alerter = Client().active_stack.alerter

def notify_on_failure() -> None:

"""Notifies user on step failure. Used in Hook."""

step_context = get_step_context()

if step_context.pipeline_run.config.extra["notify_on_failure"]:

if alerter:

alerter.post(message=build_message(status="failed"))

else:

logger.error(message=build_message(status="failed"))

Using the OpenAI ChatGPT failure hook

The OpenAI ChatGPT failure hook is a hook that uses the OpenAI integration to generate a possible fix for whatever exception caused the step to fail. It is quite easy to use. (You will need a valid OpenAI API key that has correctly set up billing for this.)

Note that using this integration will incur charges on your OpenAI account.

First, ensure that you have the OpenAI integration installed and have stored your API key within a ZenML secret:

zenml integration install openai