Huggingface.js 文档
@huggingface/hub
并获得增强的文档体验
开始使用
@huggingface/hub
类
接口
- AuthInfo
- CachedFileInfo
- CachedRepoInfo
- CachedRevisionInfo
- CommitData
- CommitDeletedEntry
- CommitFile
- CommitInfo
- CommitOutput
- Credentials
- DatasetEntry
- FileDownloadInfoOutput
- HFCacheInfo
- LfsPathInfo
- ListFileEntry
- ModelEntry
- OAuthResult
- PathInfo
- RepoId
- SafetensorsIndexJson
- SafetensorsShardFileInfo
- SecurityFileStatus
- SpaceEntry
- SpaceResourceConfig
- SpaceResourceRequirement
- SpaceRuntime
- TensorInfo
- UserInfo
- WhoAmIApp
- WhoAmIOrg
- WhoAmIUser
类型别名
AccessToken
Ƭ AccessToken: string
实际上是 hf_${string}
,但为了方便,使用字符串类型
定义在
AccessTokenRole
Ƭ AccessTokenRole: "admin"
| "write"
| "contributor"
| "read"
定义在
AuthType
Ƭ AuthType: "access_token"
| "app_token"
| "app_token_as_user"
定义在
CommitOperation
Ƭ CommitOperation: CommitDeletedEntry
| CommitFile
定义在
CommitParams
Ƭ CommitParams: { abortSignal?
: AbortSignal
; branch?
: string
; description?
: string
; fetch?
: typeof __type
; hubUrl?
: string
; isPullRequest?
: boolean
; operations
: CommitOperation
[] ; parentCommit?
: string
; repo
: RepoDesignation
; title
: string
; useWebWorkers?
: boolean
| { minSize?
: number
; poolSize?
: number
} } & Partial
\<CredentialsParams
>
定义在
CommitProgressEvent
Ƭ CommitProgressEvent: { event
: "phase"
; phase
: "preuploading"
| "uploadingLargeFiles"
| "committing"
} | { event
: "fileProgress"
; path
: string
; progress
: number
; state
: "hashing"
| "uploading"
}
定义在
ContentSource
Ƭ ContentSource: Blob
| URL
定义于
Dtype
Ƭ Dtype: "F64"
| "F32"
| "F16"
| "BF16"
| "I64"
| "I32"
| "I16"
| "I8"
| "U8"
| "BOOL"
定义于
hub/src/lib/parse-safetensors-metadata.ts:45
PipelineType
Ƭ PipelineType: keyof typeof PIPELINE_DATA
定义于
tasks/dist/commonjs/pipelines.d.ts:437
RepoDesignation
Ƭ RepoDesignation: RepoId
| RepoFullName
定义于
RepoFullName
Ƭ RepoFullName: string
| `spaces/${string}` | `datasets/${string}`
定义于
RepoType
Ƭ RepoType: "space"
| "dataset"
| "model"
定义于
SafetensorsFileHeader
Ƭ SafetensorsFileHeader: Record
\<TensorName
, TensorInfo
> & { __metadata__
: Record
\<string
, string
> }
定义于
hub/src/lib/parse-safetensors-metadata.ts:53
SafetensorsParseFromRepo
Ƭ SafetensorsParseFromRepo: { header
: SafetensorsFileHeader
; parameterCount?
: Partial
\<Record
\<Dtype
, number
>> ; sharded
: false
} | { headers
: SafetensorsShardedHeaders
; index
: SafetensorsIndexJson
; parameterCount?
: Partial
\<Record
\<Dtype
, number
>> ; sharded
: true
}
定义于
hub/src/lib/parse-safetensors-metadata.ts:67
SafetensorsShardedHeaders
Ƭ SafetensorsShardedHeaders: Record
\<FileName
, SafetensorsFileHeader
>
定义于
hub/src/lib/parse-safetensors-metadata.ts:65
SpaceHardwareFlavor
Ƭ SpaceHardwareFlavor: "cpu-basic"
| "cpu-upgrade"
| "t4-small"
| "t4-medium"
| "l4x1"
| "l4x4"
| "a10g-small"
| "a10g-large"
| "a10g-largex2"
| "a10g-largex4"
| "a100-large"
| "v5e-1x1"
| "v5e-2x2"
| "v5e-2x4"
定义于
SpaceSdk
Ƭ SpaceSdk: "streamlit"
| "gradio"
| "docker"
| "static"
定义于
SpaceStage
Ƭ SpaceStage: "NO_APP_FILE"
| "CONFIG_ERROR"
| "BUILDING"
| "BUILD_ERROR"
| "RUNNING"
| "RUNNING_BUILDING"
| "RUNTIME_ERROR"
| "DELETING"
| "PAUSED"
| "SLEEPING"
定义于
TensorName
Ƭ TensorName: string
定义于
hub/src/lib/parse-safetensors-metadata.ts:44
WhoAmI
Ƭ WhoAmI: WhoAmIApp
| WhoAmIOrg
| WhoAmIUser
定义于
变量
DATASET _ EXPANDABLE _ KEYS
• Const
DATASET_EXPANDABLE_KEYS: readonly ["author"
, "cardData"
, "citation"
, "createdAt"
, "disabled"
, "description"
, "downloads"
, "downloadsAllTime"
, "gated"
, "gitalyUid"
, "lastModified"
, "likes"
, "paperswithcode_id"
, "private"
, "sha"
, "tags"
]
定义于
hub/src/lib/list-datasets.ts:17
DATASET _ EXPAND _ KEYS
• Const
DATASET_EXPAND_KEYS: readonly ["private"
, "downloads"
, "gated"
, "likes"
, "lastModified"
]
定义于
hub/src/lib/list-datasets.ts:9
DEFAULT _ REVISION
• Const
DEFAULT_REVISION: "main"
定义于
hub/src/lib/snapshot-download.ts:12
MODEL _ EXPANDABLE _ KEYS
• Const
MODEL_EXPANDABLE_KEYS: readonly ["author"
, "cardData"
, "config"
, "createdAt"
, "disabled"
, "downloads"
, "downloadsAllTime"
, "gated"
, "gitalyUid"
, "inferenceProviderMapping"
, "lastModified"
, "library_name"
, "likes"
, "model-index"
, "pipeline_tag"
, "private"
, "safetensors"
, "sha"
, "spaces"
, "tags"
, "transformersInfo"
]
定义于
MODEL _ EXPAND _ KEYS
• Const
MODEL_EXPAND_KEYS: readonly ["pipeline_tag"
, "private"
, "gated"
, "downloads"
, "likes"
, "lastModified"
]
定义于
REGEX _ COMMIT _ HASH
• Const
REGEX_COMMIT_HASH: RegExp
定义于
hub/src/lib/download-file-to-cache-dir.ts:11
REPO _ ID _ SEPARATOR
• Const
REPO_ID_SEPARATOR: string
= "--"
定义于
hub/src/lib/cache-management.ts:25
RE _ SAFETENSORS _ FILE
• Const
RE_SAFETENSORS_FILE: RegExp
定义于
hub/src/lib/parse-safetensors-metadata.ts:14
RE _ SAFETENSORS _ INDEX _ FILE
• Const
RE_SAFETENSORS_INDEX_FILE: RegExp
定义于
hub/src/lib/parse-safetensors-metadata.ts:15
RE _ SAFETENSORS _ SHARD _ FILE
• Const
RE_SAFETENSORS_SHARD_FILE: RegExp
定义于
hub/src/lib/parse-safetensors-metadata.ts:16
SAFETENSORS _ FILE
• Const
SAFETENSORS_FILE: "model.safetensors"
定义于
hub/src/lib/parse-safetensors-metadata.ts:10
SAFETENSORS _ INDEX _ FILE
• Const
SAFETENSORS_INDEX_FILE: "model.safetensors.index.json"
定义于
hub/src/lib/parse-safetensors-metadata.ts:11
SPACE _ EXPANDABLE _ KEYS
• Const
SPACE_EXPANDABLE_KEYS: readonly ["author"
, "cardData"
, "datasets"
, "disabled"
, "gitalyUid"
, "lastModified"
, "createdAt"
, "likes"
, "private"
, "runtime"
, "sdk"
, "sha"
, "subdomain"
, "tags"
, "models"
]
定义于
SPACE _ EXPAND _ KEYS
• Const
SPACE_EXPAND_KEYS: readonly ["sdk"
, "likes"
, "private"
, "lastModified"
]
定义于
函数
_ _ internal _ sha256
▸ __internal_sha256(buffer
, opts?
): AsyncGenerator
\<number
, string
>
参数
Name | Type |
---|---|
buffer | Blob |
opts? | Object |
opts.abortSignal? | AbortSignal |
opts.useWebWorker? | boolean | { minSize? : number ; poolSize? : number } |
返回值
AsyncGenerator
\<number
, string
>
hex-encoded sha
Yields
progress (0-1)
定义于
checkRepoAccess
▸ checkRepoAccess(params
): Promise
\<void
>
检查我们是否拥有仓库的读取权限。
如果我们没有访问权限,则抛出 HubApiError 错误。HubApiError.statusCode 将为 401、403 或 404。
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; repo : RepoDesignation } & Partial \<CredentialsParams > |
返回值
Promise
\<void
>
定义于
hub/src/lib/check-repo-access.ts:13
commit
▸ commit(params
): Promise
\<CommitOutput
>
参数
Name | Type |
---|---|
params | CommitParams |
返回值
Promise
\<CommitOutput
>
定义于
commitIter
▸ commitIter(params
): AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
目前的内部函数,由 commit 使用。
稍后可以公开以提供更精细的进度信息
参数
Name | Type |
---|---|
params | CommitParams |
返回值
AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
定义于
countCommits
▸ countCommits(params
): Promise
\<number
>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; repo : RepoDesignation ; revision? : string } & Partial \<CredentialsParams > |
返回值
Promise
\<number
>
定义于
hub/src/lib/count-commits.ts:7
createRepo
▸ createRepo(params
): Promise
\<{ repoUrl
: string
}>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; files? : { content : ArrayBuffer | Blob ; path : string }[] ; hubUrl? : string ; license? : string ; private? : boolean ; repo : RepoDesignation ; sdk? : SpaceSdk | undefined } & CredentialsParams |
返回值
Promise
\<{ repoUrl
: string
}>
定义于
datasetInfo
▸ datasetInfo\<T
>(params
): Promise
\<DatasetEntry
& Pick
\<ApiDatasetInfo
, T
>>
类型参数
Name | Type |
---|---|
T | extends "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "paperswithcode_id" | "sha" | "citation" | "description" | "downloadsAllTime" = never |
参数
Name | Type |
---|---|
params | { additionalFields? : T [] ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; name : string ; revision? : string } & Partial \<CredentialsParams > |
返回值
Promise
\<DatasetEntry
& Pick
\<ApiDatasetInfo
, T
>>
定义于
deleteFile
▸ deleteFile(params
): Promise
\<CommitOutput
>
参数
Name | Type |
---|---|
params | { branch? : string ; commitDescription? : string ; commitTitle? : string ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; isPullRequest? : boolean ; parentCommit? : string ; path : string ; repo : RepoDesignation } & CredentialsParams |
返回值
Promise
\<CommitOutput
>
定义于
deleteFiles
▸ deleteFiles(params
): Promise
\<CommitOutput
>
参数
Name | Type |
---|---|
params | { branch? : string ; commitDescription? : string ; commitTitle? : string ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; isPullRequest? : boolean ; parentCommit? : string ; paths : string [] ; repo : RepoDesignation } & CredentialsParams |
返回值
Promise
\<CommitOutput
>
定义于
deleteRepo
▸ deleteRepo(params
): Promise
\<void
>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; repo : RepoDesignation } & CredentialsParams |
返回值
Promise
\<void
>
定义于
downloadFile
▸ downloadFile(params
): Promise
\<Response
| null
>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; path : string ; range? : [number , number ] ; raw? : boolean ; repo : RepoDesignation ; revision? : string } & Partial \<CredentialsParams > |
返回值
Promise
\<Response
| null
>
文件不存在时返回 null
定义于
hub/src/lib/download-file.ts:10
downloadFileToCacheDir
▸ downloadFileToCacheDir(params
): Promise
<string
>
下载给定文件,如果该文件尚未存在于本地缓存中。
参数
Name | Type |
---|---|
params | { cacheDir? : string ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise <Response >(input : string | URL | Request , init? : RequestInit ) => Promise <Response > ; hubUrl? : string ; path : string ; raw? : boolean ; repo : RepoDesignation ; revision? : string } & Partial <CredentialsParams > |
返回值
Promise
<string
>
指向 blob 对象的符号链接
定义于
hub/src/lib/download-file-to-cache-dir.ts:41
fileDownloadInfo
▸ fileDownloadInfo(params
): Promise
<FileDownloadInfoOutput
| null
>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise <Response >(input : string | URL | Request , init? : RequestInit ) => Promise <Response > ; hubUrl? : string ; noContentDisposition? : boolean ; path : string ; raw? : boolean ; repo : RepoDesignation ; revision? : string } & Partial <CredentialsParams > |
返回值
Promise
<FileDownloadInfoOutput
| null
>
文件不存在时返回 null
定义于
hub/src/lib/file-download-info.ts:18
fileExists
▸ fileExists(params
): Promise
<boolean
>
参数
Name | Type |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise <Response >(input : string | URL | Request , init? : RequestInit ) => Promise <Response > ; hubUrl? : string ; path : string ; repo : RepoDesignation ; revision? : string } & Partial <CredentialsParams > |
返回值
Promise
<boolean
>
定义于
getBlobStat
▸ getBlobStat(blobPath
, blobStats
): Promise
<Stats
>
参数
Name | Type |
---|---|
blobPath | string |
blobStats | Map <string , Stats > |
返回值
Promise
<Stats
>
定义于
hub/src/lib/cache-management.ts:244
getHFHubCachePath
▸ getHFHubCachePath(): string
返回值
string
定义于
hub/src/lib/cache-management.ts:19
getRepoFolderName
▸ getRepoFolderName(«destructured»
): string
参数
Name | Type |
---|---|
«destructured» | RepoId |
返回值
string
定义于
hub/src/lib/cache-management.ts:27
listCommits
▸ listCommits(params
): AsyncGenerator
<CommitData
>
参数
Name | Type |
---|---|
params | { batchSize? : number ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise <Response >(input : string | URL | Request , init? : RequestInit ) => Promise <Response > ; hubUrl? : string ; repo : RepoDesignation ; revision? : string } & Partial <CredentialsParams > |
返回值
AsyncGenerator
<CommitData
>
定义于
hub/src/lib/list-commits.ts:17
listDatasets
▸ listDatasets<T
>(params?
): AsyncGenerator
<DatasetEntry
& Pick
<ApiDatasetInfo
, T
>>
类型参数
Name | Type |
---|---|
T | extends "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "paperswithcode_id" | "sha" | "citation" | "description" | "downloadsAllTime" = never |
参数
Name | Type |
---|---|
params? | { search?: { query?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; } | undefined; hubUrl?: string | undefined; additionalFields?: T[] | undefined; limit?: number | undefined; fetch?: { …; } | undefined; } & Partial<…> |
返回值
AsyncGenerator
<DatasetEntry
& Pick
<ApiDatasetInfo
, T
>>
定义于
hub/src/lib/list-datasets.ts:47
listFiles
▸ listFiles(params
): AsyncGenerator
<ListFileEntry
>
列出文件夹中的文件。要列出目录中的 *所有* 文件,请使用 params.recursive 设置为 true
来调用它。
参数
Name | Type |
---|---|
params | { expand? : boolean ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; path? : string ; recursive? : boolean ; repo : RepoDesignation ; revision? : string } & Partial \<CredentialsParams > |
返回
AsyncGenerator
\<ListFileEntry
>
定义于
listModels
▸ listModels\<T
>(params?
): AsyncGenerator
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
类型参数
Name | Type |
---|---|
T | 继承自 "spaces" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "downloadsAllTime" | "config" | "inferenceProviderMapping" | "library_name" | "model-index" | "safetensors" | "transformersInfo" = never |
参数
Name | Type |
---|---|
params? | { search?: { query?: string | undefined; owner?: string | undefined; task?: “other” | “text-classification” | “token-classification” | “table-question-answering” | “question-answering” | … 还有 50 多个 … | undefined; tags?: string[] | undefined; inferenceProviders?: string[] | undefined; } | undefined; hubUrl?: strin… |
返回
AsyncGenerator
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
定义于
listSpaces
▸ listSpaces\<T
>(params?
): AsyncGenerator
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
类型参数
Name | Type |
---|---|
T | 继承自 "models" | "datasets" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "subdomain" | "runtime" = never |
参数
Name | Type |
---|---|
params? | { search?: { query?: string | undefined; owner?: string | undefined; tags?: string[] | undefined; } | undefined; hubUrl?: string | undefined; fetch?: { (input: URL | RequestInfo, init?: RequestInit | undefined): Promise\<…>; (input: string | … 还有 1 个 … | Request, init?: RequestInit | undefined): Promise\<…>; }… |
返回
AsyncGenerator
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
定义于
modelInfo
▸ modelInfo\<T
>(params
): Promise
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
类型参数
Name | Type |
---|---|
T | 继承自 "spaces" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "downloadsAllTime" | "config" | "inferenceProviderMapping" | "library_name" | "model-index" | "safetensors" | "transformersInfo" = never |
参数
Name | Type |
---|---|
params | { additionalFields? : T [] ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; name : string ; revision? : string } & Partial \<CredentialsParams > |