Hub Python Library
  • 🌍GET STARTED
    • Home
    • Quickstart
    • Installation
  • 🌍HOW-TO GUIDES
    • Overview
    • Download files
    • Upload files
    • BAFileSystem
    • Repository
    • Search
    • Inference
    • Community Tab
    • Collections
    • Cache
    • Model Cards
    • Manage your Space
    • Integrate a library
    • Webhooks server
  • 🌍CONCEPTUAL GUIDES
    • Git vs HTTP paradigm
  • 🌍REFERENCE
    • Overview
    • Login and logout
    • Environment variables
    • Managing local and online repositories
    • BOINC AI Hub API
    • Downloading files
    • Mixins & serialization methods
    • Inference Client
    • BaFileSystem
    • Utilities
    • Discussions and Pull Requests
    • Cache-system reference
    • Repo Cards and Repo Card Data
    • Space runtime
    • Collections
    • TensorBoard logger
    • Webhooks server
Powered by GitBook
On this page
  • Interact with Discussions and Pull Requests
  • Retrieve Discussions and Pull Requests from the Hub
  • Create and edit a Discussion or Pull Request programmatically
  • Push changes to a Pull Request
  • See also
  1. HOW-TO GUIDES

Community Tab

PreviousInferenceNextCollections

Last updated 1 year ago

Interact with Discussions and Pull Requests

The boincai_hub library provides a Python interface to interact with Pull Requests and Discussions on the Hub. Visit for a deeper view of what Discussions and Pull Requests on the Hub are, and how they work under the hood.

Retrieve Discussions and Pull Requests from the Hub

The HfApi class allows you to retrieve Discussions and Pull Requests on a given repo:

Copied

>>> from boincai_hub import get_repo_discussions
>>> for discussion in get_repo_discussions(repo_id="bigscience/bloom-1b3"):
...     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 returns a that yields objects. To get all the Discussions in a single list, run:

Copied

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

Copied

>>> from boincai_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 [...]',
)

In case of a Pull Request, you can retrieve the raw git diff with DiscussionWithDetails.diff. All the commits of the Pull Request are listed in DiscussionWithDetails.events.

Create and edit a Discussion or Pull Request programmatically

Copied

>>> from boincai_hub import metadata_update

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

Copied

>>> from boincai_hub import create_discussion, create_pull_request

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

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

Push changes to a Pull Request

Coming soon !

See also

The object returned by contains high-level overview of the Discussion or Pull Request. You can also get more detailed information using :

returns a object, which is a subclass of with more detailed information about the Discussion or Pull Request. Information includes all the comments, status changes, and renames of the Discussion via DiscussionWithDetails.events.

The class also offers ways to create and edit Discussions and Pull Requests. You will need an to create and edit Discussions or Pull Requests.

The simplest way to propose changes on a repo on the Hub is via the API: just set the create_pr parameter to True. This parameter is also available on other methods that wrap :

You can also use (respectively ) to create a Discussion (respectively a Pull Request) on a repo. Opening a Pull Request this way can be useful if you need to work on changes locally. Pull Requests opened this way will be in "draft" mode.

Managing Pull Requests and Discussions can be done entirely with the class. For example:

to add comments

to edit comments

to rename a Discussion or Pull Request

to open or close a Discussion / Pull Request

to merge a Pull Request

Visit the documentation page for an exhaustive reference of all available methods.

For a more detailed reference, visit the and the documentation page.

🌍
the dedicated documentation page
generator
Discussion
Discussion
HfApi.get_repo_discussions()
HfApi.get_discussion_details()
HfApi.get_discussion_details()
DiscussionWithDetails
Discussion
HfApi
access token
create_commit()
create_commit()
upload_file()
upload_folder()
delete_file()
delete_folder()
metadata_update()
HfApi.create_discussion()
HfApi.create_pull_request()
HfApi
comment_discussion()
edit_discussion_comment()
rename_discussion()
change_discussion_status()
merge_pull_request()
HfApi
Discussions and Pull Requests
hf_api