HfHub.Discussions (HfHub v0.2.0)

Copy Markdown View Source

Discussions and Pull Requests API for HuggingFace Hub.

This module provides functions to interact with discussions and pull requests on HuggingFace Hub repositories.

Examples

# List discussions for a model
{:ok, discussions} = HfHub.Discussions.list("bert-base-uncased")

# Get details for a specific discussion
{:ok, details} = HfHub.Discussions.get("my-model", 42)

# Create a new discussion
{:ok, disc} = HfHub.Discussions.create("my-model", "Feature request",
  description: "Please add support for...", token: "hf_xxx")

# Add a comment
{:ok, comment} = HfHub.Discussions.comment("my-model", 42, "Thanks!")

Summary

Types

repo_type()

@type repo_type() :: :model | :dataset | :space

status()

@type status() :: :open | :closed | :merged | :draft | :all

Functions

change_status(repo_id, discussion_num, new_status, opts \\ [])

@spec change_status(String.t(), non_neg_integer(), status(), keyword()) ::
  {:ok, HfHub.Discussions.Discussion.t()} | {:error, term()}

Changes the status of a discussion.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)
  • :comment - Optional comment explaining the status change

Examples

{:ok, disc} = HfHub.Discussions.change_status("my-model", 42, :closed, comment: "Resolved")

close(repo_id, discussion_num, opts \\ [])

@spec close(String.t(), non_neg_integer(), keyword()) ::
  {:ok, HfHub.Discussions.Discussion.t()} | {:error, term()}

Closes a discussion.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)
  • :comment - Optional comment explaining the status change

Examples

{:ok, disc} = HfHub.Discussions.close("my-model", 42, comment: "Fixed in v2.0")

comment(repo_id, discussion_num, content, opts \\ [])

@spec comment(String.t(), non_neg_integer(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.Comment.t()} | {:error, term()}

Adds a comment to a discussion.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)

Examples

{:ok, comment} = HfHub.Discussions.comment("my-model", 42, "Thanks for reporting!")

create(repo_id, title, opts \\ [])

@spec create(String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.DiscussionDetails.t()} | {:error, term()}

Creates a new discussion.

Options

  • :token - Authentication token (required)
  • :description - Discussion body/description
  • :repo_type - Repository type (default: :model)

Examples

{:ok, disc} = HfHub.Discussions.create("my-model", "Feature request",
  description: "Please add support for...")

create_pr(repo_id, title, opts \\ [])

@spec create_pr(String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.DiscussionDetails.t()} | {:error, term()}

Creates a new pull request.

Options

  • :token - Authentication token (required)
  • :description - Pull request body/description
  • :repo_type - Repository type (default: :model)

Examples

{:ok, pr} = HfHub.Discussions.create_pr("my-model", "Add new feature",
  description: "This PR adds...")

edit_comment(repo_id, discussion_num, comment_id, new_content, opts \\ [])

@spec edit_comment(String.t(), non_neg_integer(), String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.Comment.t()} | {:error, term()}

Edits an existing comment.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)

Examples

{:ok, comment} = HfHub.Discussions.edit_comment("my-model", 42, "abc123", "Updated content")

get(repo_id, discussion_num, opts \\ [])

@spec get(String.t(), non_neg_integer(), keyword()) ::
  {:ok, HfHub.Discussions.DiscussionDetails.t()} | {:error, term()}

Gets details for a specific discussion.

Includes full content and all comments/events.

Options

  • :token - Authentication token
  • :repo_type - Repository type (default: :model)

Examples

{:ok, details} = HfHub.Discussions.get("my-model", 42)
details.events  # List of comments, status changes, etc.

hide_comment(repo_id, discussion_num, comment_id, opts \\ [])

@spec hide_comment(String.t(), non_neg_integer(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.Comment.t()} | {:error, term()}

Hides a comment from view.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)

Examples

{:ok, comment} = HfHub.Discussions.hide_comment("my-model", 42, "abc123")

list(repo_id, opts \\ [])

@spec list(
  String.t(),
  keyword()
) :: {:ok, [HfHub.Discussions.Discussion.t()]} | {:error, term()}

Lists discussions for a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type (default: :model)
  • :author - Filter by author username
  • :status - Filter by status (:open, :closed, :merged, :draft, :all)

Examples

{:ok, discussions} = HfHub.Discussions.list("bert-base-uncased")
{:ok, open} = HfHub.Discussions.list("my-model", status: :open)

merge_pr(repo_id, discussion_num, opts \\ [])

@spec merge_pr(String.t(), non_neg_integer(), keyword()) ::
  {:ok, HfHub.Discussions.Discussion.t()} | {:error, term()}

Merges a pull request.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)
  • :comment - Optional merge comment

Examples

{:ok, pr} = HfHub.Discussions.merge_pr("my-model", 42)

rename(repo_id, discussion_num, new_title, opts \\ [])

@spec rename(String.t(), non_neg_integer(), String.t(), keyword()) ::
  {:ok, HfHub.Discussions.Discussion.t()} | {:error, term()}

Renames a discussion.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)

Examples

{:ok, disc} = HfHub.Discussions.rename("my-model", 42, "New Title")

reopen(repo_id, discussion_num, opts \\ [])

@spec reopen(String.t(), non_neg_integer(), keyword()) ::
  {:ok, HfHub.Discussions.Discussion.t()} | {:error, term()}

Reopens a closed discussion.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type (default: :model)
  • :comment - Optional comment explaining the status change

Examples

{:ok, disc} = HfHub.Discussions.reopen("my-model", 42)