HuggingfaceClient.Hub.Commits (huggingface_client v0.1.0)

Copy Markdown View Source

High-level commit helpers: upload files, delete files.

These wrap the low-level /api/{type}s/{repo}/commit/{branch} endpoint, mirroring uploadFile, uploadFiles, and deleteFile(s) from @huggingface/hub.

Upload a single file

{:ok, commit} = HuggingfaceClient.Hub.Commits.upload_file("my-user/my-model",
  path: "README.md",
  content: "# My Model",
  access_token: "hf_..."
)

Upload multiple files

{:ok, commit} = HuggingfaceClient.Hub.Commits.upload_files("my-user/my-model",
  files: [
    %{path: "model.py", content: model_code},
    %{path: "config.json", content: Jason.encode!(config)}
  ],
  commit_title: "Add model files",
  access_token: "hf_..."
)

Delete files

{:ok, commit} = HuggingfaceClient.Hub.Commits.delete_files("my-user/my-model",
  paths: ["old_model.bin", "scratch.txt"],
  access_token: "hf_..."
)

Summary

Functions

Deletes a single file.

Deletes one or more files from a repository.

Uploads a single file to a repository.

Uploads multiple files to a repository in a single commit.

Functions

delete_file(repo, opts)

@spec delete_file(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}

Deletes a single file.

Options

  • :path — file path to delete (required)

delete_files(repo, opts)

@spec delete_files(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}

Deletes one or more files from a repository.

Options

  • :paths — list of file paths to delete (required)
  • :commit_title — commit message (default: "Delete N files")
  • :branch, :is_pull_request, :parent_commit, :type — standard options

upload_file(repo, opts)

@spec upload_file(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}

Uploads a single file to a repository.

Options

  • :path — destination path in the repo (required)
  • :content — file content as binary or string (required)
  • :commit_title — commit message (default: "Add {path}")
  • :commit_description — extended commit message
  • :branch — target branch (default: "main")
  • :is_pull_request — create a PR instead of direct commit (default: false)
  • :parent_commit — SHA to use as parent (for conflict detection)
  • :type — repo type (default: :model)
  • :access_token — HF token (required)

upload_files(repo, opts)

@spec upload_files(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}

Uploads multiple files to a repository in a single commit.

Each file in :files should be %{path: "...", content: binary_or_string}.

Options

  • :files — list of %{path, content} maps (required)
  • :commit_title — commit message
  • :branch, :is_pull_request, :parent_commit, :type — see upload_file/2