huggingface

package module
v0.0.0-...-c3f5ac0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 17 Imported by: 3

README

Yet another Go package to download from HuggingFace Hub

Features

See whole documentation at Go Reference

codecov

Documentation

Overview

Package huggingface is the best library to fetch files from an huggingface repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthRequest

func AuthRequest(ctx context.Context, h *http.Client, method, url, token string, hdr map[string]string) (*http.Response, error)

AuthRequest does an authenticated HTTP request with a Bearer token, which retries automatically 429 and 5xx.

Method must be HEAD or GET.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the client for https://huggingface.co/.

func New

func New(token string) (*Client, error)

New returns a new *Client client to download files and list repositories.

It uses the endpoints as described at https://huggingface.co/docs/hub/api.

Respects the following environment variables described at https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables: HF_HOME, HF_HUB_CACHE, HF_TOKEN_PATh and HF_TOKEN.

func (*Client) EnsureFile

func (c *Client) EnsureFile(ctx context.Context, ref ModelRef, revision, file string) (string, error)

EnsureFile ensures the file is available, downloads it otherwise.

Similar to https://huggingface.co/docs/huggingface_hub/package_reference/file_download

func (*Client) EnsureSnapshot

func (c *Client) EnsureSnapshot(ctx context.Context, ref ModelRef, revision string, glob []string) ([]string, error)

EnsureSnapshot ensures files available from the snapshot, downloads them otherwise.

Downloads files concurrently.

Similar to https://huggingface.co/docs/huggingface_hub/package_reference/file_download#huggingface_hub.snapshot_download

func (*Client) GetFileInfo

func (c *Client) GetFileInfo(ctx context.Context, ref ModelRef, revision, file string) (string, string, int64, error)

GetFileInfo retrieves the information about the file.

Returns the commitish, etag, size.

func (*Client) GetModelInfo

func (c *Client) GetModelInfo(ctx context.Context, m *Model, ref string) error

GetModelInfo fills the supplied Model with information from the HuggingFace Hub.

Use "main" as ref unless you need a specific commit.

type Model

type Model struct {
	ModelRef
	// Upstream is the upstream repo when the model is based on another one.
	Upstream ModelRef

	// Tensor is the native quantization of the weight. This is found in
	// config.json in Upstream.
	TensorType safetensors.DType
	// Number of weights. Has direct impact on performance and memory usage.
	NumWeights int64
	// ContentLength is the number of tokens that the LLM can take as context
	// when relevant. Has impact on performance and memory usage. Not relevant
	// for image generators.
	ContextLength int
	// License is the license of the weights, for whatever that means. Use the
	// name for well known licences (e.g. "Apache v2.0" or "MIT") or an URL for
	// custom licenses.
	License string
	// LicenseURL is the URL to the license file.
	LicenseURL string
	// Files is the list of files in the repository.
	Files []string
	// Created is the time the repository was created. It can be at the earliest
	// 2022-03-02 as documented at
	// https://huggingface.co/docs/hub/api#repo-listing-api.
	Created time.Time
	// Modified is the last time the repository was modified.
	Modified time.Time
	// SHA of the reference requested.
	SHA string
	// contains filtered or unexported fields
}

Model is a model stored on https://huggingface.co

type ModelRef

type ModelRef struct {
	// Author is the owner, either a person or an organization.
	Author string
	// Repo is the name of the repository owned by the Author.
	Repo string
	// contains filtered or unexported fields
}

ModelRef is a reference to a model stored on https://huggingface.co

func (*ModelRef) RepoID

func (m *ModelRef) RepoID() string

RepoID is a shorthand to return .m.Author + "/" + m.Repo

func (*ModelRef) URL

func (m *ModelRef) URL() string

URL returns the Model's canonical URL.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL