Hub Python Library documentation

Tartışmalar ve Çekme İstekleriyle Etkileşime Girin

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v2.4.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Tartışmalar ve Çekme İstekleriyle Etkileşime Girin

huggingface_hub kütüphanesi, Hub'daki Pull Request'ler ve Tartışmalarla etkileşime girmek için bir Python arayüzü sağlar. Hub'daki Tartışmaların ve Pull Request'lerin ne olduğunu ve alt yapıda nasıl çalıştığını daha derinlemesine incelemek için özel dokümantasyon sayfasını ziyaret edin.

Hub'dan Tartışmaları ve Çekme İsteklerini Al

HfApi sınıfı, belirli bir depodaki Tartışmaları ve Birleştirme İsteklerini (Pull Request) almanızı sağlar:

>>> from huggingface_hub import get_repo_discussions
>>> for discussion in get_repo_discussions(repo_id="bigscience/bloom"):
...     print(f"{discussion.num} - {discussion.title}, pr: {discussion.is_pull_request}")

# 11 - Add Flax weights, pr: True
# 10 - Update README.md, pr: True
# 9 - Training languages in the model card, pr: True
# 8 - Update tokenizer_config.json, pr: True
# 7 - Slurm training script, pr: False
[...]

HfApi.get_repo_discussions, yazar, tür (Pull Request veya Discussion) ve durum (open veya closed) bazında filtreleme destekler:

>>> from huggingface_hub import get_repo_discussions
>>> for discussion in get_repo_discussions(
...    repo_id="bigscience/bloom",
...    author="ArthurZ",
...    discussion_type="pull_request",
...    discussion_status="open",
... ):
...     print(f"{discussion.num} - {discussion.title} by {discussion.author}, pr: {discussion.is_pull_request}")

# 19 - Add Flax weights by ArthurZ, pr: True

HfApi.get_repo_discussions, Discussion nesneleri üreten bir generator döndürür. Tüm Discussion'ları tek bir listede almak için şunu çalıştırın:

>>> from huggingface_hub import get_repo_discussions
>>> discussions_list = list(get_repo_discussions(repo_id="bert-base-uncased"))

HfApi.get_repo_discussions() tarafından döndürülen Discussion nesnesi, Tartışma veya Pull Request'in yüksek düzeyde bir özetini içerir. Daha ayrıntılı bilgi almak için HfApi.get_discussion_details() işlevini de kullanabilirsiniz:

>>> from huggingface_hub import get_discussion_details

>>> get_discussion_details(
...     repo_id="bigscience/bloom-1b3",
...     discussion_num=2
... )
DiscussionWithDetails(
    num=2,
    author='cakiki',
    title='Update VRAM memory for the V100s',
    status='open',
    is_pull_request=True,
    events=[
        DiscussionComment(type='comment', author='cakiki', ...),
        DiscussionCommit(type='commit', author='cakiki', summary='Update VRAM memory for the V100s', oid='1256f9d9a33fa8887e1c1bf0e09b4713da96773a', ...),
    ],
    conflicting_files=[],
    target_branch='refs/heads/main',
    merge_commit_oid=None,
    diff='diff --git a/README.md b/README.md\nindex a6ae3b9294edf8d0eda0d67c7780a10241242a7e..3a1814f212bc3f0d3cc8f74bdbd316de4ae7b9e3 100644\n--- a/README.md\n+++ b/README.md\n@@ -132,7 +132,7 [...]',
)

HfApi.get_discussion_details(), Discussion'ın daha ayrıntılı bir alt sınıfı olan ve Tartışma veya Pull Request hakkında daha detaylı bilgi içeren bir DiscussionWithDetails nesnesi döndürür. Bilgiler, DiscussionWithDetails.events üzerinden Tartışmanın tüm yorumlarını, durum değişikliklerini ve yeniden adlandırmalarını içerir.

Bir Pull Request söz konusuysa, ham git diff'i DiscussionWithDetails.diff ile alabilirsiniz. Pull Request'lerin tüm commit'leri DiscussionWithDetails.events içinde listelenir.

Bir Tartışma veya Çekme İsteğini programatik olarak oluşturma ve düzenleme

HfApi sınıfı, Discussion ve Pull Request oluşturma ve düzenleme için de yollar sunar. Discussion veya Pull Request oluşturmak ve düzenlemek için bir erişim belirteci gerekir.

Hub'daki bir depoda değişiklik önermenin en basit yolu create_commit() API'sini kullanmaktır: create_pr parametresini True olarak ayarlayın. Bu parametre, create_commit() işlevini saran diğer yöntemlerde de kullanılabilir:

>>> from huggingface_hub import metadata_update

>>> metadata_update(
...     repo_id="username/repo_name",
...     metadata={"tags": ["computer-vision", "awesome-model"]},
...     create_pr=True,
... )

Bir depo üzerinde Discussion (sırasıyla Pull Request) oluşturmak için HfApi.create_discussion() (sırasıyla HfApi.create_pull_request()) işlevini de kullanabilirsiniz. Değişiklikler üzerinde yerel olarak çalışmanız gerekiyorsa, bir Pull Request’i bu şekilde açmak faydalı olabilir. Bu şekilde açılan Pull Request’ler "draft" modunda olacaktır.

>>> from huggingface_hub import create_discussion, create_pull_request

>>> create_discussion(
...     repo_id="username/repo-name",
...     title="Hi from the huggingface_hub library!",
...     token="<insert your access token here>",
... )
DiscussionWithDetails(...)

>>> create_pull_request(
...     repo_id="username/repo-name",
...     title="Hi from the huggingface_hub library!",
...     token="<insert your access token here>",
... )
DiscussionWithDetails(..., is_pull_request=True)

HfApi sınıfı kullanılarak Pull Request'lerin ve Tartışmaların yönetimi tamamen yapılabilir. Örneğin:

Tüm kullanılabilir yöntemlerin kapsamlı bir referansı için HfApi dokümantasyon sayfasını ziyaret edin.

CLI'den Tartışmaları ve Çekme İsteklerini Yönetme

Yukarıdaki tüm işlemler, hf discussions aracılığıyla komut satırından da kullanılabilir. Bu, Python kodu yazmadan betikleme, CI hatları veya hızlı etkileşimler için kullanışlıdır.

# List open discussions and PRs on a repo
hf discussions list bigscience/bloom

# List discussions on a dataset repo
hf discussions list nebius/SWE-rebench-V2 --type dataset

# Get info for a specific discussion, including its comment thread
hf discussions info bigscience/bloom 2

# Create a new discussion
hf discussions create username/repo-name --title "Bug report" --body "Description here"

# Create a pull request
hf discussions create username/repo-name --title "Fix typo" --pull-request

# Comment on a discussion or PR
hf discussions comment username/repo-name 5 --body "LGTM!"

# Attach a screenshot to a comment
hf discussions comment username/repo-name 5 --body "Here is the fix:" --attach screenshot.png

# Merge a pull request
hf discussions merge username/repo-name 5 --yes

# Show the diff of a pull request
hf discussions diff username/repo-name 5

Tüm seçeneklerin listesi için hf discussions --help komutunu çalıştırın veya CLI referansına bakın.

Değişiklikleri bir Pull Request'e gönder

Çok yakında!

Bkz.

Daha ayrıntılı bir referans için Tartışmalar ve Çekme İstekleri ile hf_api dokümantasyon sayfasını ziyaret edin.

Update on GitHub