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 = SendNotification.from_integration(slack_hook)
# 자동화를 생성합니다.
automation = api.create_automation(
event >> action,
name="my-automation",
description="'custom-metric'이 10을 초과할 때마다 Slack 메시지를 보냅니다.",
)