import wandb
from wandb.automations import OnRunMetric, RunEvent, SendNotification
api = wandb.Api()
project = api.project("<my-project>", entity="<my-team>")
# チームの最初の Slack インテグレーションを使用する
slack_hook = next(api.slack_integrations(entity="<my-team>"))
# トリガーとなるイベントを作成する
event = OnRunMetric(
scope=project,
filter=RunEvent.metric("custom-metric") > 10,
)
# イベント発生時に実行する action を作成する
action = SendNotification.from_integration(slack_hook)
# オートメーションを作成する
automation = api.create_automation(
event >> action,
name="my-automation",
description="Send a Slack message whenever 'custom-metric' exceeds 10.",
)