Huggingface.js 文档
@huggingface/hub
并获得增强的文档体验
开始使用
@huggingface/hub
类
接口
- AuthInfo
- CachedFileInfo
- CachedRepoInfo
- CachedRevisionInfo
- CommitData
- CommitDeletedEntry
- CommitFile
- CommitInfo
- CommitOutput
- Credentials
- DatasetEntry
- FileDownloadInfoOutput
- HFCacheInfo
- LfsPathInfo
- ListFileEntry
- ModelConfig
- ModelEntry
- OAuthResult
- PathInfo
- QuantizationConfig
- RepoId
- SafetensorsIndexJson
- SafetensorsShardFileInfo
- SecurityFileStatus
- SpaceEntry
- SpaceResourceConfig
- SpaceResourceRequirement
- SpaceRuntime
- TensorInfo
- UserInfo
- WhoAmIApp
- WhoAmIOrg
- WhoAmIUser
- XetFileInfo
类型别名
AccessToken
Ƭ AccessToken: string
实际上是 hf_${string}
,但为方便起见,使用字符串类型。
定义于
packages/hub/src/types/public.ts:15
AccessTokenRole
Ƭ AccessTokenRole: "admin"
| "write"
| "contributor"
| "read"
定义于
packages/hub/src/types/public.ts:70
AuthType
Ƭ AuthType: "access_token"
| "app_token"
| "app_token_as_user"
定义于
packages/hub/src/types/public.ts:72
CommitOperation
Ƭ CommitOperation: CommitDeletedEntry
| CommitFile
定义于
packages/hub/src/lib/commit.ts:54
CommitParams
Ƭ CommitParams: { abortSignal?
: AbortSignal
; branch?
: string
; description?
: string
; fetch?
: typeof __type
; hubUrl?
: string
; isPullRequest?
: boolean
; maxFolderDepth?
: number
; operations
: CommitOperation
[] ; parentCommit?
: string
; repo
: RepoDesignation
; title
: string
; useWebWorkers?
: boolean
| { minSize?
: number
; poolSize?
: number
} } & Partial
\<CredentialsParams
>
定义于
packages/hub/src/lib/commit.ts:57
CommitProgressEvent
Ƭ CommitProgressEvent: { event
: "phase"
; phase
: "preuploading"
| "uploadingLargeFiles"
| "committing"
} | { event
: "fileProgress"
; path
: string
; progress
: number
; state
: "hashing"
| "uploading"
}
定义于
packages/hub/src/lib/commit.ts:112
ContentSource
Ƭ ContentSource: Blob
| URL
定义于
packages/hub/src/lib/commit.ts:35
Dtype
Ƭ Dtype: "F64"
| "F32"
| "F16"
| "F8_E4M3"
| "F8_E5M2"
| "E8M0"
| "F6_E3M2"
| "F6_E2M3"
| "F4"
| "FP4"
| "BF16"
| "I64"
| "I32"
| "I16"
| "I8"
| "U16"
| "U8"
| "UE8"
| "BOOL"
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:45
PipelineType
Ƭ PipelineType: keyof typeof PIPELINE_DATA
定义于
packages/tasks/dist/commonjs/pipelines.d.ts:372
RepoDesignation
Ƭ RepoDesignation: RepoId
| RepoFullName
定义于
packages/hub/src/types/public.ts:12
RepoFullName
Ƭ RepoFullName: string
| `spaces/${string}` | `datasets/${string}`
定义于
packages/hub/src/types/public.ts:10
RepoType
Ƭ RepoType: "space"
| "dataset"
| "model"
定义于
packages/hub/src/types/public.ts:3
SafetensorsFileHeader
Ƭ SafetensorsFileHeader: Record
\<TensorName
, TensorInfo
> & { __metadata__
: { total_parameters?
: string
| number
} & Record
\<string
, string
> }
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:72
SafetensorsParseFromRepo
Ƭ SafetensorsParseFromRepo: { header
: SafetensorsFileHeader
; parameterCount?
: Partial
\<Record
\<Dtype
, number
>> ; parameterTotal?
: number
; sharded
: false
} | { headers
: SafetensorsShardedHeaders
; index
: SafetensorsIndexJson
; parameterCount?
: Partial
\<Record
\<Dtype
, number
>> ; parameterTotal?
: number
; sharded
: true
}
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:86
SafetensorsShardedHeaders
Ƭ SafetensorsShardedHeaders: Record
\<FileName
, SafetensorsFileHeader
>
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:84
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"
定义于
packages/hub/src/types/public.ts:40
SpaceSdk
Ƭ SpaceSdk: "streamlit"
| "gradio"
| "docker"
| "static"
定义于
packages/hub/src/types/public.ts:56
SpaceStage
Ƭ SpaceStage: "NO_APP_FILE"
| "CONFIG_ERROR"
| "BUILDING"
| "BUILD_ERROR"
| "RUNNING"
| "RUNNING_BUILDING"
| "RUNTIME_ERROR"
| "DELETING"
| "PAUSED"
| "SLEEPING"
定义于
packages/hub/src/types/public.ts:58
TensorName
Ƭ TensorName: string
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:44
WhoAmI
Ƭ WhoAmI: WhoAmIApp
| WhoAmIOrg
| WhoAmIUser
定义于
packages/hub/src/lib/who-am-i.ts:50
变量
DATASET _ EXPANDABLE _ KEYS
• Const
DATASET_EXPANDABLE_KEYS: 只读 ["author"
, "cardData"
, "citation"
, "createdAt"
, "disabled"
, "description"
, "downloads"
, "downloadsAllTime"
, "gated"
, "gitalyUid"
, "lastModified"
, "likes"
, "paperswithcode_id"
, "private"
, "sha"
, "tags"
]
定义于
packages/hub/src/lib/list-datasets.ts:17
DATASET _ EXPAND _ KEYS
• Const
DATASET_EXPAND_KEYS: 只读 ["private"
, "downloads"
, "gated"
, "likes"
, "lastModified"
]
定义于
packages/hub/src/lib/list-datasets.ts:9
DEFAULT _ REVISION
• Const
DEFAULT_REVISION: "main"
定义于
packages/hub/src/lib/snapshot-download.ts:12
HUB _ URL
• Const
HUB_URL: "https://huggingface.co"
定义于
MODEL _ EXPANDABLE _ KEYS
• Const
MODEL_EXPANDABLE_KEYS: 只读 ["author"
, "cardData"
, "config"
, "createdAt"
, "disabled"
, "downloads"
, "downloadsAllTime"
, "gated"
, "gitalyUid"
, "inferenceProviderMapping"
, "lastModified"
, "library_name"
, "likes"
, "model-index"
, "pipeline_tag"
, "private"
, "safetensors"
, "sha"
, "spaces"
, "tags"
, "transformersInfo"
]
定义于
packages/hub/src/lib/list-models.ts:19
MODEL _ EXPAND _ KEYS
• Const
MODEL_EXPAND_KEYS: 只读 ["pipeline_tag"
, "private"
, "gated"
, "downloads"
, "likes"
, "lastModified"
]
定义于
packages/hub/src/lib/list-models.ts:10
REGEX _ COMMIT _ HASH
• Const
REGEX_COMMIT_HASH: RegExp
定义于
packages/hub/src/lib/download-file-to-cache-dir.ts:15
REPO _ ID _ SEPARATOR
• Const
REPO_ID_SEPARATOR: string
= "--"
定义于
packages/hub/src/lib/cache-management.ts:25
RE _ SAFETENSORS _ FILE
• Const
RE_SAFETENSORS_FILE: RegExp
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:14
RE _ SAFETENSORS _ INDEX _ FILE
• Const
RE_SAFETENSORS_INDEX_FILE: RegExp
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:15
RE _ SAFETENSORS _ SHARD _ FILE
• Const
RE_SAFETENSORS_SHARD_FILE: RegExp
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:16
SAFETENSORS _ FILE
• Const
SAFETENSORS_FILE: "model.safetensors"
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:10
SAFETENSORS _ INDEX _ FILE
• Const
SAFETENSORS_INDEX_FILE: "model.safetensors.index.json"
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:11
SPACE _ EXPANDABLE _ KEYS
• Const
SPACE_EXPANDABLE_KEYS: 只读 ["author"
, "cardData"
, "datasets"
, "disabled"
, "gitalyUid"
, "lastModified"
, "createdAt"
, "likes"
, "private"
, "runtime"
, "sdk"
, "sha"
, "subdomain"
, "tags"
, "models"
]
定义于
packages/hub/src/lib/list-spaces.ts:15
SPACE _ EXPAND _ KEYS
• Const
SPACE_EXPAND_KEYS: 只读 ["sdk"
, "likes"
, "private"
, "lastModified"
]
定义于
packages/hub/src/lib/list-spaces.ts:9
函数
_ _ internal _ sha256
▸ __internal_sha256(buffer
, opts?
): AsyncGenerator
\<number
, string
>
参数
名称 | 类型 |
---|---|
buffer | Blob |
opts? | Object |
opts.abortSignal? | AbortSignal |
opts.useWebWorker? | boolean | { minSize? : number ; poolSize? : number } |
返回值
AsyncGenerator
\<number
, string
>
十六进制编码的 sha
产生
进度 (0-1)
定义于
packages/hub/src/utils/sha256.ts:72
checkRepoAccess
▸ checkRepoAccess(params
): Promise
\<void
>
检查我们是否拥有对仓库的读访问权限。
如果没有访问权限,则抛出 HubApiError 错误。HubApiError.statusCode 将为 401、403 或 404。
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/check-repo-access.ts:13
提交
▸ commit(params
): Promise
\<CommitOutput
>
参数
名称 | 类型 |
---|---|
params | CommitParams |
返回值
Promise
\<CommitOutput
>
定义于
packages/hub/src/lib/commit.ts:565
commitIter
▸ commitIter(params
): AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
目前是内部函数,用于提交。
以后可以暴露出来,提供更精细的进度信息
参数
名称 | 类型 |
---|---|
params | CommitParams |
返回值
AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
定义于
packages/hub/src/lib/commit.ts:129
countCommits
▸ countCommits(params
): Promise
\<number
>
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/count-commits.ts:7
createBranch
▸ createBranch(params
): Promise
\<void
>
参数
名称 | 类型 | 描述 |
---|---|---|
params | Object | - |
params.accessToken? | 字符串 | - |
params.branch | 字符串 | 要创建的分支名称 |
params.empty? | boolean | 用于创建没有提交的空分支。 |
params.fetch? | (input : URL | RequestInfo , init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > | MDN 参考 |
params.hubUrl? | 字符串 | - |
params.overwrite? | boolean | 用于在分支已存在时覆盖分支。如果只指定 overwrite ,而不指定 revision /empty ,并且分支已存在,则不会执行任何操作。 |
params.repo | RepoDesignation | - |
params.revision? | 字符串 | 用于创建分支的修订版本。默认为默认分支。使用 empty: true 创建一个空分支。 |
返回值
Promise
\<void
>
定义于
packages/hub/src/lib/create-branch.ts:6
createCollection
▸ createCollection(params
): Promise
\<{ slug
: string
}>
参数
名称 | 类型 |
---|---|
params | { collection : ApiCreateCollectionPayload ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string } & Partial \<CredentialsParams > |
返回值
Promise
\<{ slug
: string
}>
定义于
packages/hub/src/lib/create-collection.ts:7
createRepo
▸ createRepo(params
): Promise
\<{ repoUrl
: string
}>
参数
名称 | 类型 |
---|---|
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
}>
定义于
packages/hub/src/lib/create-repo.ts:9
datasetInfo
▸ datasetInfo\<T
>(params
): Promise
\<DatasetEntry
& Pick
\<ApiDatasetInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | 扩展 "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "paperswithcode_id" | "sha" | "citation" | "description" | "downloadsAllTime" = never |
参数
名称 | 类型 |
---|---|
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
>>
定义于
packages/hub/src/lib/dataset-info.ts:9
deleteBranch
▸ deleteBranch(params
): Promise
\<void
>
参数
名称 | 类型 | 描述 |
---|---|---|
params | Object | - |
params.accessToken? | 字符串 | - |
params.branch | 字符串 | 要删除的分支名称 |
params.fetch? | (input : URL | RequestInfo , init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > | MDN 参考 |
params.hubUrl? | 字符串 | - |
params.repo | RepoDesignation | - |
返回
Promise
\<void
>
定义于
packages/hub/src/lib/delete-branch.ts:6
deleteCollection
▸ deleteCollection(params
): Promise
\<void
>
参数
名称 | 类型 |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; slug : string } & Partial \<CredentialsParams > |
返回
Promise
\<void
>
定义于
packages/hub/src/lib/delete-collection.ts:6
deleteFile
▸ deleteFile(params
): Promise
\<CommitOutput
>
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/delete-file.ts:5
deleteFiles
▸ deleteFiles(params
): Promise
\<CommitOutput
>
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/delete-files.ts:5
deleteRepo
▸ deleteRepo(params
): Promise
\<void
>
参数
名称 | 类型 |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; repo : RepoDesignation } & CredentialsParams |
返回
Promise
\<void
>
定义于
packages/hub/src/lib/delete-repo.ts:7
downloadFile
▸ downloadFile(params
): Promise
\<Blob
| null
>
参数
名称 | 类型 |
---|---|
params | { downloadInfo? : FileDownloadInfoOutput ; 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 ; xet? : boolean } & Partial \<CredentialsParams > |
返回
Promise
\<Blob
| null
>
文件不存在时返回null
定义于
packages/hub/src/lib/download-file.ts:11
downloadFileToCacheDir
▸ downloadFileToCacheDir(params
): Promise
\<string
>
如果文件尚未存在于本地缓存中,则下载给定文件。
参数
名称 | 类型 |
---|---|
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对象的符号链接
定义于
packages/hub/src/lib/download-file-to-cache-dir.ts:45
fileDownloadInfo
▸ fileDownloadInfo(params
): Promise
\<FileDownloadInfoOutput
| null
>
参数
名称 | 类型 |
---|---|
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
定义于
packages/hub/src/lib/file-download-info.ts:27
fileExists
▸ fileExists(params
): Promise
\<boolean
>
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/file-exists.ts:7
getBlobStat
▸ getBlobStat(blobPath
, blobStats
): Promise
\<Stats
>
参数
名称 | 类型 |
---|---|
blobPath | 字符串 |
blobStats | Map \<string , Stats > |
返回
Promise
\<Stats
>
定义于
packages/hub/src/lib/cache-management.ts:244
getHFHubCachePath
▸ getHFHubCachePath(): string
返回
字符串
定义于
packages/hub/src/lib/cache-management.ts:19
getRepoFolderName
▸ getRepoFolderName(«destructured»
): string
参数
名称 | 类型 |
---|---|
«解构» | RepoId |
返回
字符串
定义于
packages/hub/src/lib/cache-management.ts:27
listCollections
▸ listCollections(params?
): AsyncGenerator
\<ApiCollectionInfo
>
参数
名称 | 类型 |
---|---|
params? | { search?: { owner?: string[] | undefined; item?: string[] | undefined; q?: string | undefined; } | undefined; sort?: “lastModified” | “trending” | “upvotes” | undefined; limit?: number | undefined; hubUrl?: string | undefined; fetch?: { …; } | undefined; } & Partial\<…> |
返回
AsyncGenerator
\<ApiCollectionInfo
>
定义于
packages/hub/src/lib/list-collections.ts:12
listCommits
▸ listCommits(params
): AsyncGenerator
\<CommitData
>
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/list-commits.ts:17
listDatasets
▸ listDatasets\<T
>(params?
): AsyncGenerator
\<DatasetEntry
& Pick
\<ApiDatasetInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | 扩展 "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "paperswithcode_id" | "sha" | "citation" | "description" | "downloadsAllTime" = never |
参数
名称 | 类型 |
---|---|
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
>>
定义于
packages/hub/src/lib/list-datasets.ts:47
listFiles
▸ listFiles(params
): AsyncGenerator
\<ListFileEntry
>
列出文件夹中的文件。要列出目录中的所有文件,请将params.recursive设置为true
并调用它。
参数
名称 | 类型 |
---|---|
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
>
定义于
packages/hub/src/lib/list-files.ts:42
listModels
▸ listModels\<T
>(params?
): AsyncGenerator
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | extends "spaces" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "downloadsAllTime" | "config" | "inferenceProviderMapping" | "library_name" | "model-index" | "safetensors" | "transformersInfo" = never |
参数
名称 | 类型 |
---|---|
params? | { search?: { query?: string | undefined; owner?: string | undefined; task?: “other” | “text-classification” | “token-classification” | “table-question-answering” | “question-answering” | … 50 more … | undefined; tags?: string[] | undefined; inferenceProviders?: string[] | undefined; } | undefined; hubUrl?: strin… |
返回
AsyncGenerator
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
定义于
packages/hub/src/lib/list-models.ts:55
listSpaces
▸ listSpaces\<T
>(params?
): AsyncGenerator
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | extends "models" | "datasets" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "subdomain" | "runtime" = never |
参数
名称 | 类型 |
---|---|
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 more … | Request, init?: RequestInit | undefined): Promise\<…>; }… |
返回
AsyncGenerator
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
定义于
packages/hub/src/lib/list-spaces.ts:44
modelInfo
▸ modelInfo\<T
>(params
): Promise
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | extends "spaces" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "downloadsAllTime" | "config" | "inferenceProviderMapping" | "library_name" | "model-index" | "safetensors" | "transformersInfo" = never |
参数
名称 | 类型 |
---|---|
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
\<ModelEntry
& Pick
\<ApiModelInfo
, T
>>
定义于
packages/hub/src/lib/model-info.ts:10
oauthHandleRedirect
▸ oauthHandleRedirect(opts?
): Promise
\<OAuthResult
>
在 OAuth 供应商重定向回应用程序后调用。
还有一个辅助函数 oauthHandleRedirectIfPresent,如果 URL 的查询参数中包含 OAuth 代码,它将调用 oauthHandleRedirect
,否则返回 false
。
参数
名称 | 类型 | 描述 |
---|---|---|
opts? | Object | - |
opts.codeVerifier? | 字符串 | 由 oauthLoginUrl 生成的 codeVerifier 默认值 ts localStorage.getItem("huggingface.co:oauth:code_verifier") |
opts.hubUrl? | 字符串 | Hub 的 URL。默认为 HUB_URL。 |
opts.nonce? | 字符串 | 由 oauthLoginUrl 生成的 nonce 默认值 ts localStorage.getItem("huggingface.co:oauth:nonce") |
opts.redirectedUrl? | 字符串 | 要分析的 URL。 默认值 ts window.location.href |
返回
Promise
\<OAuthResult
>
定义于
packages/hub/src/lib/oauth-handle-redirect.ts:123
oauthHandleRedirectIfPresent
▸ oauthHandleRedirectIfPresent(opts?
): Promise
\<OAuthResult
| false
>
在 OAuth 供应商重定向回应用程序后调用。
如果 URL 的查询参数中不包含 OAuth 代码,则返回 false,否则调用 oauthHandleRedirect。
根据您的应用程序,您可能希望直接调用 oauthHandleRedirect。
参数
名称 | 类型 | 描述 |
---|---|---|
opts? | Object | - |
opts.codeVerifier? | 字符串 | 由 oauthLoginUrl 生成的 codeVerifier 默认值 ts localStorage.getItem("huggingface.co:oauth:code_verifier") |
opts.hubUrl? | 字符串 | Hub 的 URL。默认为 HUB_URL。 |
opts.nonce? | 字符串 | 由 oauthLoginUrl 生成的 nonce 默认值 ts localStorage.getItem("huggingface.co:oauth:nonce") |
opts.redirectedUrl? | 字符串 | 要分析的 URL。 默认值 ts window.location.href |
返回
Promise
\<OAuthResult
| false
>
定义于
packages/hub/src/lib/oauth-handle-redirect.ts:293
oauthLoginUrl
▸ oauthLoginUrl(opts?
): Promise
\<string
>
使用“通过 Hub 登录”来认证用户,并获取 OAuth 用户信息/访问令牌。
返回要重定向到的 URL。在用户重定向回您的应用程序后,调用 oauthHandleRedirect
以获取 OAuth 用户信息/访问令牌。
当从启用了 OAuth 的静态空间内部调用时,它将从空间配置中加载配置,否则您至少需要指定 OAuth 应用程序的客户端 ID。
参数
名称 | 类型 | 描述 |
---|---|---|
opts? | Object | - |
opts.clientId? | 字符串 | OAuth 客户端 ID。对于静态空间,您可以省略此项,它将从空间配置中加载,只要 README.md 的元数据中存在 hf_oauth: true 。对于其他空间,只要 README.md 的元数据中存在 hf_oauth: true ,后端就可以在 OAUTH_CLIENT_ID 环境变量中获取。您还可以在 https://huggingface.co/settings/connected-applications 创建一个开发人员应用程序并使用其客户端 ID。 |
opts.hubUrl? | 字符串 | - |
opts.localStorage? | Object | 如果提供,将填充 OAuth 流程中使用的代码验证器和 nonce,而不是使用 localStorage。当调用 oauthHandleRedirectIfPresent 或 oauthHandleRedirect 时,您需要提供相同的值。 |
opts.localStorage.codeVerifier? | 字符串 | - |
opts.localStorage.nonce? | 字符串 | - |
opts.redirectUrl? | 字符串 | 重定向 URI,默认为当前 URL。对于空间,允许空间内的任何 URL。对于开发人员应用程序,您可以在 https://huggingface.co/settings/connected-applications 将您想要的任何 URL 添加到允许的重定向 URI 列表中。 |
opts.scopes? | 字符串 | OAuth 范围,以空格分隔的范围列表。对于静态空间,您可以省略此项,它将从空间配置中加载,只要 README.md 的元数据中存在 hf_oauth: true 。对于其他空间,只要 README.md 的元数据中存在 hf_oauth: true ,后端就可以在 OAUTH_SCOPES 环境变量中获取。默认为“openid profile”。您还可以在 https://huggingface.co/settings/connected-applications 创建一个开发人员应用程序并使用其范围。有关可用范围的列表,请参阅 https://huggingface.co/docs/hub/oauth。 |
opts.state? | 字符串 | 要传递给 OAuth 提供商的状态,该状态将在重定向后调用 oauthLogin 时返回。 |
返回
Promise
\<string
>
示例
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
const oauthResult = await oauthHandleRedirectIfPresent();
if (!oauthResult) {
// If the user is not logged in, redirect to the login page
window.location.href = await oauthLoginUrl();
}
// You can use oauthResult.accessToken, oauthResult.accessTokenExpiresAt and oauthResult.userInfo
console.log(oauthResult);
(理论上,通过更改 hubUrl
,此函数可用于验证支持 PKCE 和 OpenID Connect 的任何 OAuth 提供程序的用户,但目前仅在 Hugging Face Hub 上进行过测试。)
定义于
packages/hub/src/lib/oauth-login-url.ts:31
parseRepoType
▸ parseRepoType(type
): RepoType
参数
名称 | 类型 |
---|---|
类型 | 字符串 |
返回
定义于
packages/hub/src/lib/cache-management.ts:254
parseSafetensorsMetadata
▸ parseSafetensorsMetadata(params
): Promise
\<SetRequired
\<SafetensorsParseFromRepo
, "parameterCount"
>>
使用智能范围请求分析 Hugging Face 上托管模型的 model.safetensors.index.json 或 model.safetensors 文件,以提取其元数据。
参数
名称 | 类型 |
---|---|
params | { computeParametersCount : true ; 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
\<SetRequired
\<SafetensorsParseFromRepo
, "parameterCount"
>>
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:230
▸ parseSafetensorsMetadata(params
): Promise
\<SafetensorsParseFromRepo
>
参数
名称 | 类型 |
---|---|
params | { computeParametersCount? : boolean ; 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
\<SafetensorsParseFromRepo
>
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:252
parseSafetensorsShardFilename
▸ parseSafetensorsShardFilename(filename
): SafetensorsShardFileInfo
| null
参数
名称 | 类型 |
---|---|
文件名 | 字符串 |
返回
SafetensorsShardFileInfo
| null
定义于
packages/hub/src/lib/parse-safetensors-metadata.ts:24
pathsInfo
▸ pathsInfo(params
): Promise
\<PathInfo
& { lastCommit
: CommitInfo
; securityFileStatus
: SecurityFileStatus
}[]>
参数
名称 | 类型 |
---|---|
params | { expand : true ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; paths : string [] ; repo : RepoDesignation ; revision? : string } & Partial \<CredentialsParams > |
返回
Promise
\<PathInfo
& { lastCommit
: CommitInfo
; securityFileStatus
: SecurityFileStatus
}[]>
定义于
packages/hub/src/lib/paths-info.ts:37
▸ pathsInfo(params
): Promise
\<PathInfo
[]>
参数
名称 | 类型 |
---|---|
params | { expand? : boolean ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string ; paths : string [] ; repo : RepoDesignation ; revision? : string } & Partial \<CredentialsParams > |
返回
Promise
\<PathInfo
[]>
定义于
packages/hub/src/lib/paths-info.ts:50
repoExists
▸ repoExists(params
): Promise
\<boolean
>
参数
名称 | 类型 | 描述 |
---|---|---|
params | Object | - |
params.accessToken? | 字符串 | - |
params.fetch? | (input : URL | RequestInfo , init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > | 要使用的自定义 fetch 函数,而不是默认函数,例如,用于使用代理或编辑标头。 |
params.hubUrl? | 字符串 | - |
params.repo | RepoDesignation | - |
params.revision? | 字符串 | 一个可选的 Git 修订 ID,可以是分支名称、标签或提交哈希。 |
返回
Promise
\<boolean
>
定义于
packages/hub/src/lib/repo-exists.ts:6
scanCacheDir
▸ scanCacheDir(cacheDir?
): Promise
\<HFCacheInfo
>
参数
名称 | 类型 | 默认值 |
---|---|---|
缓存目录 | undefined | string | undefined |
返回
Promise
\<HFCacheInfo
>
定义于
packages/hub/src/lib/cache-management.ts:72
scanCachedRepo
▸ scanCachedRepo(repoPath
): Promise
\<CachedRepoInfo
>
参数
名称 | 类型 |
---|---|
repo路径 | 字符串 |
返回
Promise
\<CachedRepoInfo
>
定义于
packages/hub/src/lib/cache-management.ts:114
scanRefsDir
▸ scanRefsDir(refsPath
, refsByHash
): Promise
\<void
>
参数
名称 | 类型 |
---|---|
refs路径 | 字符串 |
refsByHash | Map \<string , string []> |
返回
Promise
\<void
>
定义于
packages/hub/src/lib/cache-management.ts:204
scanSnapshotDir
▸ scanSnapshotDir(revisionPath
, cachedFiles
, blobStats
): Promise
\<void
>
参数
名称 | 类型 |
---|---|
修订路径 | 字符串 |
缓存文件 | CachedFileInfo [] |
blobStats | Map \<string , Stats > |
返回
Promise
\<void
>
定义于
packages/hub/src/lib/cache-management.ts:219
snapshotDownload
▸ snapshotDownload(params
): Promise
\<string
>
在缓存目录 getHFHubCachePath 中下载给定修订的整个存储库。您可以使用 scanCachedRepo 列出所有缓存的存储库
参数
名称 | 类型 |
---|---|
params | { cacheDir? : string ; 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
\<string
>
备注
它在内部使用 downloadFileToCacheDir。
定义于
packages/hub/src/lib/snapshot-download.ts:19
spaceInfo
▸ spaceInfo\<T
>(params
): Promise
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
类型参数
名称 | 类型 |
---|---|
T | extends "models" | "datasets" | "author" | "cardData" | "disabled" | "gitalyUid" | "createdAt" | "tags" | "sha" | "subdomain" | "runtime" = never |
参数
名称 | 类型 |
---|---|
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
\<SpaceEntry
& Pick
\<ApiSpaceInfo
, T
>>
定义于
packages/hub/src/lib/space-info.ts:10
uploadFile
▸ uploadFile(params
): Promise
\<CommitOutput
>
参数
名称 | 类型 |
---|---|
params | { abortSignal? : AbortSignal ; branch? : string ; commitDescription? : string ; commitTitle? : string ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; file : URL | File | { content : ContentSource ; path : string } ; hubUrl? : string ; isPullRequest? : boolean ; parentCommit? : string ; repo : RepoDesignation ; useWebWorkers? : boolean | { minSize? : number ; poolSize? : number } } & Partial \<CredentialsParams > |
返回
Promise
\<CommitOutput
>
定义于
packages/hub/src/lib/upload-file.ts:5
uploadFiles
▸ uploadFiles(params
): Promise
\<CommitOutput
>
参数
名称 | 类型 |
---|---|
params | { abortSignal? : AbortSignal ; branch? : string ; commitDescription? : string ; commitTitle? : string ; fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; files : (URL | File | { content : ContentSource ; path : string })[] ; hubUrl? : string ; isPullRequest? : boolean ; maxFolderDepth? : number ; parentCommit? : string ; repo : RepoDesignation ; useWebWorkers? : boolean | { minSize? : number ; poolSize? : number } } & Partial \<CredentialsParams > |
返回
Promise
\<CommitOutput
>
定义于
packages/hub/src/lib/upload-files.ts:5
uploadFilesWithProgress
▸ uploadFilesWithProgress(params
): AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
带进度的上传
上传的进度事件需要 XMLHttpRequest 可用。将 useWebWorkers 设置为 true 以便获取哈希处理的进度事件。
参数
名称 | 类型 |
---|---|
params | { abortSignal? : AbortSignal ; branch? : string ; commitDescription? : string ; commitTitle? : string ; files : (URL | File | { content : ContentSource ; path : string })[] ; hubUrl? : string ; isPullRequest? : boolean ; maxFolderDepth? : number ; parentCommit? : string ; repo : RepoDesignation ; useWebWorkers? : boolean | { minSize? : number ; poolSize? : number } } & Partial \<CredentialsParams > |
返回
AsyncGenerator
\<CommitProgressEvent
, CommitOutput
>
定义于
packages/hub/src/lib/upload-files-with-progress.ts:20
whoAmI
▸ whoAmI(params
): Promise
\<WhoAmI
& { auth
: AuthInfo
}>
参数
名称 | 类型 |
---|---|
params | { fetch? : (input : URL | RequestInfo, init? : RequestInit ) => Promise \<Response >(input : string | URL | Request , init? : RequestInit ) => Promise \<Response > ; hubUrl? : string } & CredentialsParams |
返回
Promise
\<WhoAmI
& { auth
: AuthInfo
}>
定义于
packages/hub/src/lib/who-am-i.ts:61
< > 在 GitHub 上更新