Hub documentation

Webhooks 자동화

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Webhooks 자동화

Webhooks를 사용하면 Hugging Face에서 특정 저장소 또는 버킷의 새로운 변경 사항을 수신하거나, 특정 사용자/조직 집단에 속한 모든 저장소(본인의 저장소뿐만 아니라 모든 저장소)의 변경 사항을 수신하도록 설정할 수 있습니다.

huggingface_hub Python 클라이언트에서 create_webhook를 사용하여 Hugging Face 저장소에서 변경 사항이 발생하면 Job이 트리거되도록 웹훅을 생성합니다:

from huggingface_hub import create_webhook

# Example: Creating a webhook that triggers a Job
webhook = create_webhook(
    job_id=job_id,
    watched=[{"type": "user", "name": "your-username"}, {"type": "org", "name": "your-org-name"}],
    domains=["repo", "discussion"],
    secret="your-secret"
)

bucket에 파일이 추가되거나 삭제될 때 Job을 실행하려면, 해당 bucket을 관찰(watch)하세요:

webhook = create_webhook(
    job_id=job_id,
    watched=[{"type": "bucket", "name": "your-username/your-bucket"}],
    domains=["repo"],
    secrets={"HF_TOKEN": "hf_***"},
)

완전한 예제는 Jobs를 사용하여 버킷의 새 파일 처리를 참조하세요.

Webhook은 다음 환경 변수를 사용하여 Job을 트리거합니다:

  • WEBHOOK_PAYLOAD: JSON 문자열로 된 전체 웹훅 페이로드
  • WEBHOOK_REPO_ID: 저장소 또는 버킷 이름 (예: user/repo-name)
  • WEBHOOK_REPO_TYPE: 저장소 유형(model, dataset, space 또는 bucket)
  • WEBHOOK_SECRET: 설정된 경우, 웹훅 시크릿
  • WEBHOOK_ID: 해당 전달(delivery)에 대한 고유 식별자로, 해당 전달의 재시도(retry) 간에도 유지됩니다

Webhook 실행은 Job의 볼륨이나 시크릿을 유지하지 않습니다. Job에 필요한 HF_TOKEN과 같은 시크릿은 create_webhook에서 secrets=를 통해 전달하세요. Webhook에서 UV 스크립트를 실행하려면 hf jobs run <image> uv run <url>으로 Job을 정의해야 하며, 그렇지 않으면 hf jobs uv run은 스크립트를 볼륨에 업로드하는데, Webhook 실행에는 볼륨이 없기 때문입니다.

webhook 페이로드에는 여러 필드가 포함되어 있으며, 유용한 필드 몇 가지는 다음과 같습니다:

- event:
  - action: one of "create", "delete", "move", "update"
  - scope: string
- repo:
  - owner: string
  - headSha: string (not sent for buckets)
  - name: string
  - type: one of "dataset", "model", "space", "bucket"
- updatedFiles: for bucket file changes, the list of added and deleted files

huggingface_hub Webhooks 문서에서 웹훅에 대한 자세한 정보를 확인할 수 있습니다.

Update on GitHub