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 上更新