Huggingface.js 文档

类: HfInference

Hugging Face's logo
加入 Hugging Face 社区

并获取增强的文档体验

开始使用

类: HfInference

层级结构

  • TaskWithNoAccessToken

    HfInference

构造函数

constructor

new HfInference(accessToken?, defaultOptions?): HfInference

参数

名称 类型 默认值
accessToken string ""
defaultOptions Options {}

返回值

HfInference

定义于

inference/src/HfInference.ts:28

属性

accessToken

Private Readonly accessToken: string

定义于

inference/src/HfInference.ts:25


audioClassification

audioClassification: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<AudioClassificationReturn>

类型声明

▸ (args, options?): Promise\<AudioClassificationReturn>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制音频数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<AudioClassificationReturn>

定义于

inference/src/tasks/audio/audioClassification.ts:30


audioToAudio

audioToAudio: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<AudioToAudioReturn>

类型声明

▸ (args, options?): Promise\<AudioToAudioReturn>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制音频数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<AudioToAudioReturn>

定义于

inference/src/tasks/audio/audioToAudio.ts:35


automaticSpeechRecognition

automaticSpeechRecognition: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<AutomaticSpeechRecognitionOutput>

类型声明

▸ (args, options?): Promise\<AutomaticSpeechRecognitionOutput>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制音频数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<AutomaticSpeechRecognitionOutput>

定义于

inference/src/tasks/audio/automaticSpeechRecognition.ts:23


chatCompletion

chatCompletion: (args: {}, options?: Options) => Promise\<ChatCompletionOutput>

类型声明

▸ (args, options?): Promise\<ChatCompletionOutput>

参数
名称 类型
args 对象
options? Options
返回值

Promise\<ChatCompletionOutput>

定义于

inference/src/tasks/nlp/chatCompletion.ts:10


chatCompletionStream

chatCompletionStream: (args: {}, options?: Options) => AsyncGenerator\<ChatCompletionStreamOutput, any, unknown>

类型声明

▸ (args, options?): AsyncGenerator\<ChatCompletionStreamOutput, any, unknown>

参数
名称 类型
args 对象
options? Options
返回值

AsyncGenerator\<ChatCompletionStreamOutput, any, unknown>

定义于

inference/src/tasks/nlp/chatCompletionStream.ts:8


defaultOptions

Private Readonly defaultOptions: Options

定义于

inference/src/HfInference.ts:26


documentQuestionAnswering

documentQuestionAnswering: (args: { endpointUrl?: string ; inputs: { image: Blob | ArrayBuffer ; question: string } ; model?: string }, options?: Options) => Promise\<DocumentQuestionAnsweringOutput>

类型声明

▸ (args, options?): Promise\<DocumentQuestionAnsweringOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.image Blob | ArrayBuffer 原始图像。您可以使用浏览器中的原生 File,或 node 中的 new Blob([buffer]),或者对于 base64 图像,使用 new Blob([btoa(base64String)]),甚至 await (await fetch('...')).blob()
args.inputs.question string -
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<DocumentQuestionAnsweringOutput>

定义于

inference/src/tasks/multimodal/documentQuestionAnswering.ts:42


featureExtraction

featureExtraction: (args: { endpointUrl?: string ; inputs: string | string[] ; model?: string }, options?: Options) => Promise\<FeatureExtractionOutput>

类型声明

▸ (args, options?): Promise\<FeatureExtractionOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string | string[] 输入是用于获取特征的字符串或字符串列表。例如: “That is a happy person”。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<FeatureExtractionOutput>

定义于

inference/src/tasks/nlp/featureExtraction.ts:24


fillMask

fillMask: (args: { endpointUrl?: string ; inputs: string ; model?: string }, options?: Options) => Promise\<FillMaskOutput>

类型声明

▸ (args, options?): Promise\<FillMaskOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string -
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<FillMaskOutput>

定义于

inference/src/tasks/nlp/fillMask.ts:31


图像分类

imageClassification: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<ImageClassificationOutput>

类型声明

▸ (args, options?): Promise\<ImageClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制图像数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<ImageClassificationOutput>

定义于

inference/src/tasks/cv/imageClassification.ts:29


图像分割

imageSegmentation: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<ImageSegmentationOutput>

类型声明

▸ (args, options?): Promise\<ImageSegmentationOutput>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制图像数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<ImageSegmentationOutput>

定义于

inference/src/tasks/cv/imageSegmentation.ts:33


图像到图像

imageToImage: (args: { endpointUrl?: string ; inputs: Blob | ArrayBuffer ; model?: string ; parameters?: { guess_mode?: boolean ; guidance_scale?: number ; height?: number ; negative_prompt?: string ; num_inference_steps?: number ; prompt?: string ; strength?: number ; width?: number } }, options?: Options) => Promise\<Blob>

类型声明

▸ (args, options?): Promise\<Blob>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs Blob | ArrayBuffer 初始图像条件
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters? 对象 -
args.parameters.guess_mode? 布尔值 guess_mode 仅适用于 ControlNet 模型,默认为 False。在此模式下,即使您删除所有提示,ControlNet 编码器也会尽力识别输入图像的内容。建议 guidance_scale 在 3.0 到 5.0 之间。
args.parameters.guidance_scale? 数字 引导比例:较高的引导比例鼓励生成与文本 prompt 紧密相关的图像,但通常以降低图像质量为代价。
args.parameters.height? 数字 生成图像的高度(像素)
args.parameters.negative_prompt? string 用于图像生成的 可选负面提示
args.parameters.num_inference_steps? 数字 去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会以较慢的推理速度为代价。
args.parameters.prompt? string 用于引导图像生成的文本提示。
args.parameters.strength? 数字 strengh 参数仅适用于 SD img2img 和 alt diffusion img2img 模型。从概念上讲,表示要转换参考 image 的程度。必须介于 0 和 1 之间。 image 将用作起点,strength 越大,添加到其中的噪声就越大。去噪步骤的数量取决于最初添加的噪声量。当 strength 为 1 时,添加的噪声将最大,去噪过程将运行 num_inference_steps 中指定的完整迭代次数。因此,值为 1 本质上会忽略 image
args.parameters.width? 数字 生成图像的宽度(像素)
options? Options -
返回值

Promise\<Blob>

定义于

inference/src/tasks/cv/imageToImage.ts:61


图像到文本

imageToText: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<ImageToTextOutput>

类型声明

▸ (args, options?): Promise\<ImageToTextOutput>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制图像数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<ImageToTextOutput>

定义于

inference/src/tasks/cv/imageToText.ts:22


目标检测

objectDetection: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string }, options?: Options) => Promise\<ObjectDetectionOutput>

类型声明

▸ (args, options?): Promise\<ObjectDetectionOutput>

参数
名称 类型 描述
args 对象 -
args.data Blob | ArrayBuffer 二进制图像数据
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<ObjectDetectionOutput>

定义于

inference/src/tasks/cv/objectDetection.ts:39


问题解答

questionAnswering: (args: { endpointUrl?: string ; inputs: { context: string ; question: string } ; model?: string }, options?: Options) => Promise\<QuestionAnsweringOutput>

类型声明

▸ (args, options?): Promise\<QuestionAnsweringOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.context string -
args.inputs.question string -
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<QuestionAnsweringOutput>

定义于

inference/src/tasks/nlp/questionAnswering.ts:34


请求

request: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string ; parameters?: Record<string, unknown> } | { endpointUrl?: string ; inputs: unknown ; model?: string ; parameters?: Record<string, unknown> } | {}, options?: Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }) => Promise<unknown>

类型声明

▸ (args, options?): Promise<unknown>

参数
名称 类型
args { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string ; parameters?: Record<string, unknown> } | { endpointUrl?: string ; inputs: unknown ; model?: string ; parameters?: Record<string, unknown> } | {}
options? Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }
返回值

Promise<unknown>

定义于

inference/src/tasks/custom/request.ts:7


句子相似度

sentenceSimilarity: (args: { endpointUrl?: string ; inputs: Record<string, unknown> | Record<string, unknown>[] ; model?: string }, options?: Options) => Promise<SentenceSimilarityOutput>

类型声明

▸ (args, options?): Promise<SentenceSimilarityOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs Record<string, unknown> | Record<string, unknown>[] 输入根据模型而变化。例如,当使用 sentence-transformers/paraphrase-xlm-r-multilingual-v1 时,输入将包含一个 source_sentence 字符串和一个 sentences 字符串数组
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise<SentenceSimilarityOutput>

定义于

inference/src/tasks/nlp/sentenceSimilarity.ts:24


流式请求

streamingRequest: (args: { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string ; parameters?: Record<string, unknown> } | { endpointUrl?: string ; inputs: unknown ; model?: string ; parameters?: Record<string, unknown> } | {}, options?: Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }) => AsyncGenerator<unknown, any, unknown>

类型声明

▸ (args, options?): AsyncGenerator<unknown, any, unknown>

参数
名称 类型
args { data: Blob | ArrayBuffer ; endpointUrl?: string ; model?: string ; parameters?: Record<string, unknown> } | { endpointUrl?: string ; inputs: unknown ; model?: string ; parameters?: Record<string, unknown> } | {}
options? Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }
返回值

AsyncGenerator<unknown, any, unknown>

定义于

inference/src/tasks/custom/streamingRequest.ts:9


摘要

summarization: (args: { endpointUrl?: string ; inputs: string ; model?: string ; parameters?: { max_length?: number ; max_time?: number ; min_length?: number ; repetition_penalty?: number ; temperature?: number ; top_k?: number ; top_p?: number } }, options?: Options) => Promise<SummarizationOutput>

类型声明

▸ (args, options?): Promise<SummarizationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string 要总结的字符串
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters? 对象 -
args.parameters.max_length? 数字 (默认值: 无)。整数,用于定义输出摘要的最大 token 长度。
args.parameters.max_time? 数字 (默认值: 无)。浮点数 (0-120.0)。查询应花费的最长时间(秒)。网络可能会导致一些开销,因此这将是一个软性限制。
args.parameters.min_length? 数字 (默认值: 无)。整数,用于定义输出摘要的最小 token 长度。
args.parameters.repetition_penalty? 数字 (默认值: 无)。浮点数 (0.0-100.0)。token 在生成过程中使用的次数越多,在后续生成过程中被选中的惩罚就越大。
args.parameters.temperature? 数字 (默认值: 1.0)。浮点数 (0.0-100.0)。采样操作的温度。1 表示常规采样,0 表示始终取最高分,100.0 表示越来越接近均匀概率。
args.parameters.top_k? 数字 (默认值: 无)。整数,用于定义在采样操作中考虑的顶部 token,以创建新文本。
args.parameters.top_p? 数字 (默认值: 无)。浮点数,用于定义文本生成采样操作中的 token。在样本中添加 token,从最有可能到最不可能,直到概率之和大于 top_p。
options? Options -
返回值

Promise<SummarizationOutput>

定义于

inference/src/tasks/nlp/summarization.ts:52


表格问答

tableQuestionAnswering: (args: { endpointUrl?: string ; inputs: { query: string ; table: Record<string, string[]> } ; model?: string }, options?: Options) => Promise<TableQuestionAnsweringOutput>

类型声明

▸ (args, options?): Promise<TableQuestionAnsweringOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.query string 您想要询问表格的纯文本查询
args.inputs.table Record<string, string[]> 表示为列表字典的数据表,其中条目是标题,列表是所有值,所有列表必须具有相同的大小。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise<TableQuestionAnsweringOutput>

定义于

inference/src/tasks/nlp/tableQuestionAnswering.ts:40


表格分类

tabularClassification: (args: { endpointUrl?: string ; inputs: { data: Record<string, string[]> } ; model?: string }, options?: Options) => Promise<TabularClassificationOutput>

类型声明

▸ (args, options?): Promise<TabularClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.data Record<string, string[]> 表示为列表字典的数据表,其中条目是标题,列表是所有值,所有列表必须具有相同的大小。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<TabularClassificationOutput>

定义于

inference/src/tasks/tabular/tabularClassification.ts:24


表格回归

tabularRegression: (args: { endpointUrl?: string ; inputs: { data: Record\<string, string[]> } ; model?: string }, options?: Options) => Promise\<TabularRegressionOutput>

类型声明

▸ (args, options?): Promise\<TabularRegressionOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.data Record<string, string[]> 表示为列表字典的数据表,其中条目是标题,列表是所有值,所有列表必须具有相同的大小。
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<TabularRegressionOutput>

定义于

inference/src/tasks/tabular/tabularRegression.ts:24


文本分类

textClassification: (args: { endpointUrl?: string ; inputs: string ; model?: string }, options?: Options) => Promise\<TextClassificationOutput>

类型声明

▸ (args, options?): Promise\<TextClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string 要分类的字符串
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<TextClassificationOutput>

定义于

inference/src/tasks/nlp/textClassification.ts:26


文本生成

textGeneration: (args: {}, options?: Options) => Promise\<TextGenerationOutput>

类型声明

▸ (args, options?): Promise\<TextGenerationOutput>

参数
名称 类型
args 对象
options? Options
返回值

Promise\<TextGenerationOutput>

定义于

inference/src/tasks/nlp/textGeneration.ts:12


文本生成流

textGenerationStream: (args: {}, options?: Options) => AsyncGenerator\<TextGenerationStreamOutput, any, unknown>

类型声明

▸ (args, options?): AsyncGenerator\<TextGenerationStreamOutput, any, unknown>

参数
名称 类型
args 对象
options? Options
返回值

AsyncGenerator\<TextGenerationStreamOutput, any, unknown>

定义于

inference/src/tasks/nlp/textGenerationStream.ts:88


文本到图像

textToImage: (args: { endpointUrl?: string ; inputs: string ; model?: string ; parameters?: { guidance_scale?: number ; height?: number ; negative_prompt?: string ; num_inference_steps?: number ; width?: number } }, options?: Options) => Promise\<Blob>

类型声明

▸ (args, options?): Promise\<Blob>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string 用于生成图像的文本
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters? 对象 -
args.parameters.guidance_scale? 数字 引导比例:较高的引导比例鼓励生成与文本 prompt 紧密相关的图像,但通常以降低图像质量为代价。
args.parameters.height? 数字 生成图像的高度(像素)
args.parameters.negative_prompt? string 用于图像生成的 可选负面提示
args.parameters.num_inference_steps? 数字 去噪步骤的数量。更多的去噪步骤通常会带来更高质量的图像,但会以较慢的推理速度为代价。
args.parameters.width? 数字 生成图像的宽度(像素)
options? Options -
返回值

Promise\<Blob>

定义于

inference/src/tasks/cv/textToImage.ts:41


文本到语音

textToSpeech: (args: { endpointUrl?: string ; inputs: string ; model?: string }, options?: Options) => Promise\<Blob>

类型声明

▸ (args, options?): Promise\<Blob>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string 用于生成音频的文本
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<Blob>

定义于

inference/src/tasks/audio/textToSpeech.ts:18


tokenClassification

tokenClassification: (args: { endpointUrl?: string ; inputs: string ; model?: string ; parameters?: { aggregation_strategy?: "none" | "simple" | "first" | "average" | "max" } }, options?: Options) => Promise\<TokenClassificationOutput>

类型声明

▸ (args, options?): Promise\<TokenClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string 要分类的字符串
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters? 对象 -
args.parameters.aggregation_strategy? "none" | "simple" | "first" | "average" | "max" (默认值:simple)。有几种聚合策略:none:每个 token 都被分类,没有进一步的聚合。simple:实体根据默认模式分组(当标签相似时,B-、I- 标签会被合并)。first:与 simple 策略相同,除了单词不能以不同的标签结尾。当存在歧义时,单词将使用第一个 token 的标签。average:与 simple 策略相同,除了单词不能以不同的标签结尾。分数在 token 之间取平均值,然后应用最大标签。max:与 simple 策略相同,除了单词不能以不同的标签结尾。单词实体将是具有最高分数的 token。
options? Options -
返回值

Promise\<TokenClassificationOutput>

定义于

inference/src/tasks/nlp/tokenClassification.ts:57


translation

translation: (args: { endpointUrl?: string ; inputs: string | string[] ; model?: string }, options?: Options) => Promise\<TranslationOutput>

类型声明

▸ (args, options?): Promise\<TranslationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string | string[] 要翻译的字符串
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<TranslationOutput>

定义于

inference/src/tasks/nlp/translation.ts:24


visualQuestionAnswering

visualQuestionAnswering: (args: { endpointUrl?: string ; inputs: { image: Blob | ArrayBuffer ; question: string } ; model?: string }, options?: Options) => Promise\<VisualQuestionAnsweringOutput>

类型声明

▸ (args, options?): Promise\<VisualQuestionAnsweringOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.image Blob | ArrayBuffer 原始图像。您可以使用浏览器中的原生 File,或 node 中的 new Blob([buffer]),或者对于 base64 图像,使用 new Blob([btoa(base64String)]),甚至 await (await fetch('...')).blob()
args.inputs.question string -
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
options? Options -
返回值

Promise\<VisualQuestionAnsweringOutput>

定义于

inference/src/tasks/multimodal/visualQuestionAnswering.ts:32


zeroShotClassification

zeroShotClassification: (args: { endpointUrl?: string ; inputs: string | string[] ; model?: string ; parameters: { candidate_labels: string[] ; multi_label?: boolean } }, options?: Options) => Promise\<ZeroShotClassificationOutput>

类型声明

▸ (args, options?): Promise\<ZeroShotClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs string | string[] 字符串或字符串列表
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters 对象 -
args.parameters.candidate_labels string[] 作为输入的潜在类别的字符串列表。(最多 10 个 candidate_labels,如果需要更多,只需运行多个请求,如果使用过多的 candidate_labels,结果会产生误导。如果您想保持完全相同,您可以简单地运行 multi_label=True 并在您这边进行缩放。
args.parameters.multi_label? 布尔值 (默认值:false)布尔值,如果类可以重叠,则设置为 True
options? Options -
返回值

Promise\<ZeroShotClassificationOutput>

定义于

inference/src/tasks/nlp/zeroShotClassification.ts:34


zeroShotImageClassification

zeroShotImageClassification: (args: { endpointUrl?: string ; inputs: { image: Blob | ArrayBuffer } ; model?: string ; parameters: { candidate_labels: string[] } }, options?: Options) => Promise\<ZeroShotImageClassificationOutput>

类型声明

▸ (args, options?): Promise\<ZeroShotImageClassificationOutput>

参数
名称 类型 描述
args 对象 -
args.endpointUrl? string 要使用的端点的 URL。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认端点。如果指定,将使用此 URL 而不是默认 URL。
args.inputs 对象 -
args.inputs.image Blob | ArrayBuffer 二进制图像数据
args.model? string 要使用的模型。如果未指定,将调用 huggingface.co/api/tasks 以获取任务的默认模型。/!\\ 遗留行为允许这是一个 URL,但这已被弃用,并将在未来版本中删除。请使用 endpointUrl 参数代替。
args.parameters 对象 -
args.parameters.candidate_labels string[] 作为输入的潜在类别的字符串列表。(最多 10 个)
options? Options -
返回值

Promise\<ZeroShotImageClassificationOutput>

定义于

inference/src/tasks/cv/zeroShotImageClassification.ts:33

方法

endpoint

endpoint(endpointUrl): HfInferenceEndpoint

返回绑定到指定端点的 HfInference 的副本。

参数

名称 类型
endpointUrl string

返回值

HfInferenceEndpoint

定义于

inference/src/HfInference.ts:45

< > Update on GitHub