import wandb
from wandb.automations import OnRunMetric, RunEvent, SendNotification
api = wandb.Api()
project = api.project("<my-project>", entity="<my-team>")
# Utiliser la première intégration Slack pour l'équipe
slack_hook = next(api.slack_integrations(entity="<my-team>"))
# Créer un événement déclencheur
event = OnRunMetric(
scope=project,
filter=RunEvent.metric("custom-metric") > 10,
)
# Créer une action qui répond à l'événement
action = SendNotification.from_integration(slack_hook)
# Créer l'automatisation
automation = api.create_automation(
event >> action,
name="my-automation",
description="Envoyer un message Slack chaque fois que 'custom-metric' dépasse 10.",
)