Huggingface.js 文档
@huggingface/inference
并获得增强的文档体验
开始使用
@huggingface/inference
命名空间
类
接口
- AudioToAudioOutput
- AudioToAudioOutputElem
- BaseArgs
- BodyParams
- HeaderParams
- Options
- ProviderConfig
- TextGenerationInput
- TextGenerationOutput
- TextGenerationStreamBestOfSequence
- TextGenerationStreamDetails
- TextGenerationStreamOutput
- TextGenerationStreamPrefillToken
- TextGenerationStreamToken
- UrlParams
类型别名
AudioClassificationArgs
Ƭ AudioClassificationArgs: BaseArgs
& AudioClassificationInput
| LegacyAudioInput
定义于
inference/src/tasks/audio/audioClassification.ts:8
AudioToAudioArgs
Ƭ AudioToAudioArgs: BaseArgs
& { inputs
: Blob
} | LegacyAudioInput
定义于
inference/src/tasks/audio/audioToAudio.ts:7
AuthMethod
Ƭ AuthMethod: "none"
| "hf-token"
| "credentials-include"
| "provider-key"
定义于
AutomaticSpeechRecognitionArgs
Ƭ AutomaticSpeechRecognitionArgs: BaseArgs
& AutomaticSpeechRecognitionInput
| LegacyAudioInput
定义于
inference/src/tasks/audio/automaticSpeechRecognition.ts:10
DocumentQuestionAnsweringArgs
Ƭ DocumentQuestionAnsweringArgs: BaseArgs
& DocumentQuestionAnsweringInput
& { inputs
: DocumentQuestionAnsweringInputData
& { image
: Blob
} }
定义于
inference/src/tasks/multimodal/documentQuestionAnswering.ts:13
FeatureExtractionArgs
Ƭ FeatureExtractionArgs: BaseArgs
& FeatureExtractionInput
定义于
inference/src/tasks/nlp/featureExtraction.ts:6
FeatureExtractionOutput
Ƭ FeatureExtractionOutput: (number
| number
[] | number
[][])[]
返回的值是浮点数的多维数组(维度取决于您发送的是字符串还是字符串列表,以及是否为您应用了自动缩减,通常是 mean_pooling。这应该在模型的 README 中解释)。
定义于
inference/src/tasks/nlp/featureExtraction.ts:11
FillMaskArgs
Ƭ FillMaskArgs: BaseArgs
& FillMaskInput
定义于
inference/src/tasks/nlp/fillMask.ts:6
ImageClassificationArgs
Ƭ ImageClassificationArgs: BaseArgs
& ImageClassificationInput
| LegacyImageInput
定义于
inference/src/tasks/cv/imageClassification.ts:7
图像分割参数
Ƭ ImageSegmentationArgs: BaseArgs
& ImageSegmentationInput
| LegacyImageInput
定义于
inference/src/tasks/cv/imageSegmentation.ts:7
图像到图像参数
Ƭ ImageToImageArgs: BaseArgs
& ImageToImageInput
定义于
inference/src/tasks/cv/imageToImage.ts:7
图像到文本参数
Ƭ ImageToTextArgs: BaseArgs
& ImageToTextInput
| LegacyImageInput
定义于
inference/src/tasks/cv/imageToText.ts:8
推理提供者
Ƭ InferenceProvider: typeof INFERENCE_PROVIDERS
[number
]
定义于
推理任务
Ƭ InferenceTask: Exclude
\<PipelineType
, "other"
>
定义于
模型ID
Ƭ ModelId: string
HF 模型 ID,例如 “meta-llama/Llama-3.3-70B-Instruct”
定义于
目标检测参数
Ƭ ObjectDetectionArgs: BaseArgs
& ObjectDetectionInput
| LegacyImageInput
定义于
inference/src/tasks/cv/objectDetection.ts:7
问题回答参数
Ƭ QuestionAnsweringArgs: BaseArgs
& QuestionAnsweringInput
定义于
inference/src/tasks/nlp/questionAnswering.ts:6
请求参数
Ƭ RequestArgs: BaseArgs
& { data
: Blob
| ArrayBuffer
} | { inputs
: unknown
} | { prompt
: string
} | { text
: string
} | { audio_url
: string
} | ChatCompletionInput
& { parameters?
: Record
\<string
, unknown
> }
定义于
句子相似度参数
Ƭ SentenceSimilarityArgs: BaseArgs
& SentenceSimilarityInput
定义于
inference/src/tasks/nlp/sentenceSimilarity.ts:6
摘要参数
Ƭ SummarizationArgs: BaseArgs
& SummarizationInput
定义于
inference/src/tasks/nlp/summarization.ts:6
表格问题回答参数
Ƭ TableQuestionAnsweringArgs: BaseArgs
& TableQuestionAnsweringInput
定义于
inference/src/tasks/nlp/tableQuestionAnswering.ts:6
表格分类参数
Ƭ TabularClassificationArgs: BaseArgs
& { inputs
: { data
: Record
\<string
, string
[]> } }
定义于
inference/src/tasks/tabular/tabularClassification.ts:5
表格分类输出
Ƭ TabularClassificationOutput: number
[]
每行的预测标签列表
定义于
inference/src/tasks/tabular/tabularClassification.ts:17
表格回归参数
Ƭ TabularRegressionArgs: BaseArgs
& { inputs
: { data
: Record
\<string
, string
[]> } }
定义于
inference/src/tasks/tabular/tabularRegression.ts:5
表格回归输出
Ƭ TabularRegressionOutput: number
[]
每行的预测值列表
定义于
inference/src/tasks/tabular/tabularRegression.ts:17
文本分类参数
Ƭ TextClassificationArgs: BaseArgs
& TextClassificationInput
定义于
inference/src/tasks/nlp/textClassification.ts:6
TextGenerationStreamFinishReason
Ƭ TextGenerationStreamFinishReason: "length"
| "eos_token"
| "stop_sequence"
定义于
inference/src/tasks/nlp/textGenerationStream.ts:46
TextToImageArgs
Ƭ TextToImageArgs: BaseArgs
& TextToImageInput
定义于
inference/src/tasks/cv/textToImage.ts:8
TextToVideoArgs
Ƭ TextToVideoArgs: BaseArgs
& TextToVideoInput
定义于
inference/src/tasks/cv/textToVideo.ts:10
TextToVideoOutput
Ƭ TextToVideoOutput: Blob
定义于
inference/src/tasks/cv/textToVideo.ts:12
TokenClassificationArgs
Ƭ TokenClassificationArgs: BaseArgs
& TokenClassificationInput
定义于
inference/src/tasks/nlp/tokenClassification.ts:7
TranslationArgs
Ƭ TranslationArgs: BaseArgs
& TranslationInput
定义于
inference/src/tasks/nlp/translation.ts:6
VisualQuestionAnsweringArgs
Ƭ VisualQuestionAnsweringArgs: BaseArgs
& VisualQuestionAnsweringInput
& { inputs
: VisualQuestionAnsweringInputData
& { image
: Blob
} }
定义于
inference/src/tasks/multimodal/visualQuestionAnswering.ts:12
ZeroShotClassificationArgs
Ƭ ZeroShotClassificationArgs: BaseArgs
& ZeroShotClassificationInput
定义于
inference/src/tasks/nlp/zeroShotClassification.ts:7
ZeroShotImageClassificationArgs
Ƭ ZeroShotImageClassificationArgs: BaseArgs
& ZeroShotImageClassificationInput
| LegacyZeroShotImageClassificationInput
定义于
inference/src/tasks/cv/zeroShotImageClassification.ts:14
变量
推理 _ 提供商
• Const
INFERENCE_PROVIDERS: readonly ["black-forest-labs"
, "cerebras"
, "cohere"
, "fal-ai"
, "fireworks-ai"
, "hf-inference"
, "hyperbolic"
, "nebius"
, "novita"
, "openai"
, "replicate"
, "sambanova"
, "together"
]
定义于
函数
audioClassification
▸ audioClassification(args
, options?
): Promise
\<AudioClassificationOutput
>
此任务读取一些音频输入,并输出类别的可能性。推荐模型:superb/hubert-large-superb-er
参数
名称 | 类型 |
---|---|
args | AudioClassificationArgs |
options? | Options |
返回值
Promise
\<AudioClassificationOutput
>
定义于
inference/src/tasks/audio/audioClassification.ts:14
audioToAudio
▸ audioToAudio(args
, options?
): Promise
\<AudioToAudioOutput
[]>
此任务读取一些音频输入,并输出一个或多个音频文件。示例模型:speechbrain/sepformer-wham 执行音频源分离。
参数
名称 | 类型 |
---|---|
args | AudioToAudioArgs |
options? | Options |
返回值
Promise
\<AudioToAudioOutput
[]>
定义于
inference/src/tasks/audio/audioToAudio.ts:38
automaticSpeechRecognition
▸ automaticSpeechRecognition(args
, options?
): Promise
\<AutomaticSpeechRecognitionOutput
>
此任务读取一些音频输入,并输出音频文件中所说的词语。推荐模型(英语):facebook/wav2vec2-large-960h-lv60-self
参数
名称 | 类型 |
---|---|
args | AutomaticSpeechRecognitionArgs |
options? | Options |
返回值
Promise
\<AutomaticSpeechRecognitionOutput
>
定义于
inference/src/tasks/audio/automaticSpeechRecognition.ts:15
chatCompletion
▸ chatCompletion(args
, options?
): Promise
\<ChatCompletionOutput
>
使用聊天完成端点生成对提示的回复,使用 OpenAI 消息完成 API (无流式传输)
参数
名称 | 类型 |
---|---|
args | BaseArgs & ChatCompletionInput |
options? | Options |
返回值
Promise
\<ChatCompletionOutput
>
定义于
inference/src/tasks/nlp/chatCompletion.ts:9
chatCompletionStream
▸ chatCompletionStream(args
, options?
): AsyncGenerator
\<ChatCompletionStreamOutput
>
用于从提示词继续生成文本。与 textGeneration
相同,但返回可以一次读取一个 token 的生成器
参数
名称 | 类型 |
---|---|
args | BaseArgs & ChatCompletionInput |
options? | Options |
返回值
AsyncGenerator
\<ChatCompletionStreamOutput
>
定义于
inference/src/tasks/nlp/chatCompletionStream.ts:8
documentQuestionAnswering
▸ documentQuestionAnswering(args
, options?
): Promise
\<DocumentQuestionAnsweringOutput
[number
]>
回答文档图像上的问题。推荐模型:impira/layoutlm-document-qa。
参数
名称 | 类型 |
---|---|
args | DocumentQuestionAnsweringArgs |
options? | Options |
返回值
Promise
\<DocumentQuestionAnsweringOutput
[number
]>
定义于
inference/src/tasks/multimodal/documentQuestionAnswering.ts:19
featureExtraction
▸ featureExtraction(args
, options?
): Promise
\<FeatureExtractionOutput
>
此任务读取一些文本并输出原始浮点数值,这些数值通常用作语义数据库/语义搜索的一部分。
参数
名称 | 类型 |
---|---|
args | FeatureExtractionArgs |
options? | Options |
返回值
Promise
\<FeatureExtractionOutput
>
定义于
inference/src/tasks/nlp/featureExtraction.ts:16
fillMask
▸ fillMask(args
, options?
): Promise
\<FillMaskOutput
>
尝试用一个缺失的词(更准确地说是 token)来填补一个空缺。这是 BERT 模型的基础任务。
参数
名称 | 类型 |
---|---|
args | FillMaskArgs |
options? | Options |
返回值
Promise
\<FillMaskOutput
>
定义于
inference/src/tasks/nlp/fillMask.ts:11
imageClassification
▸ imageClassification(args
, options?
): Promise
\<ImageClassificationOutput
>
此任务读取一些图像输入并输出类别的可能性。推荐模型:google/vit-base-patch16-224
参数
名称 | 类型 |
---|---|
args | ImageClassificationArgs |
options? | Options |
返回值
Promise
\<ImageClassificationOutput
>
定义于
inference/src/tasks/cv/imageClassification.ts:13
imageSegmentation
▸ imageSegmentation(args
, options?
): Promise
\<ImageSegmentationOutput
>
此任务读取一些图像输入并输出类别的可能性以及检测到的物体的边界框。推荐模型:facebook/detr-resnet-50-panoptic
参数
名称 | 类型 |
---|---|
args | ImageSegmentationArgs |
options? | Options |
返回值
Promise
\<ImageSegmentationOutput
>
定义于
inference/src/tasks/cv/imageSegmentation.ts:13
imageToImage
▸ imageToImage(args
, options?
): Promise
\<Blob
>
此任务读取一些文本输入并输出图像。推荐模型:lllyasviel/sd-controlnet-depth
参数
名称 | 类型 |
---|---|
args | ImageToImageArgs |
options? | Options |
返回值
Promise
\<Blob
>
定义于
inference/src/tasks/cv/imageToImage.ts:13
imageToText
▸ imageToText(args
, options?
): Promise
\<ImageToTextOutput
>
此任务读取一些图像输入并输出文本描述。
参数
名称 | 类型 |
---|---|
args | ImageToTextArgs |
options? | Options |
返回值
Promise
\<ImageToTextOutput
>
定义于
inference/src/tasks/cv/imageToText.ts:12
目标检测
▸ objectDetection(args
, options?
): Promise
\<ObjectDetectionOutput
>
此任务读取一些图像输入,并输出检测到的物体的类别和边界框的可能性。推荐模型:facebook/detr-resnet-50
参数
名称 | 类型 |
---|---|
args | ObjectDetectionArgs |
options? | Options |
返回值
Promise
\<ObjectDetectionOutput
>
定义于
inference/src/tasks/cv/objectDetection.ts:13
问答
▸ questionAnswering(args
, options?
): Promise
\<QuestionAnsweringOutput
[number
]>
想要拥有一个可以回答任何问题的万事通机器人吗?。推荐模型:deepset/roberta-base-squad2
参数
名称 | 类型 |
---|---|
args | QuestionAnsweringArgs |
options? | Options |
返回值
Promise
\<QuestionAnsweringOutput
[number
]>
定义于
inference/src/tasks/nlp/questionAnswering.ts:11
请求
▸ request\<T
>(args
, options?
): Promise
\<T
>
用于向推理提供程序发出自定义调用的原始方法
类型参数
名称 |
---|
T |
参数
名称 | 类型 |
---|---|
args | RequestArgs |
options? | Options & { chatCompletion? : boolean ; task? : InferenceTask } |
返回值
Promise
\<T
>
已弃用
请使用特定的任务函数。此函数将在未来的版本中移除。
定义于
inference/src/tasks/custom/request.ts:8
句子相似度
▸ sentenceSimilarity(args
, options?
): Promise
\<SentenceSimilarityOutput
>
通过比较一个文本和一系列其他句子的嵌入向量,计算它们之间的语义相似度。
参数
名称 | 类型 |
---|---|
args | SentenceSimilarityArgs |
options? | Options |
返回值
Promise
\<SentenceSimilarityOutput
>
定义于
inference/src/tasks/nlp/sentenceSimilarity.ts:11
流式请求
▸ streamingRequest\<T
>(args
, options?
): AsyncGenerator
\<T
>
用于发出期望服务器发送事件的自定义推理调用的原始方法,并通过生成器返回响应
类型参数
名称 |
---|
T |
参数
名称 | 类型 |
---|---|
args | RequestArgs |
options? | Options & { chatCompletion? : boolean ; task? : InferenceTask } |
返回值
AsyncGenerator
\<T
>
已弃用
请使用特定的任务函数。此函数将在未来的版本中移除。
定义于
inference/src/tasks/custom/streamingRequest.ts:7
文本摘要
▸ summarization(args
, options?
): Promise
\<SummarizationOutput
>
此任务非常适合将较长的文本概括为较短的文本。请注意,某些模型具有最大输入长度。这意味着摘要不能处理整本书等。选择模型时请务必小心。
参数
名称 | 类型 |
---|---|
args | SummarizationArgs |
options? | Options |
返回值
Promise
\<SummarizationOutput
>
定义于
inference/src/tasks/nlp/summarization.ts:11
表格问答
▸ tableQuestionAnswering(args
, options?
): Promise
\<TableQuestionAnsweringOutput
[number
]>
不懂 SQL?不想深入研究大型电子表格?用简单的英语提问即可! 推荐模型:google/tapas-base-finetuned-wtq。
参数
名称 | 类型 |
---|---|
args | TableQuestionAnsweringArgs |
options? | Options |
返回值
Promise
\<TableQuestionAnsweringOutput
[number
]>
定义于
inference/src/tasks/nlp/tableQuestionAnswering.ts:11
表格分类
▸ tabularClassification(args
, options?
): Promise
\<TabularClassificationOutput
>
预测表格形式的给定特征集的目标标签。通常,您需要根据您的训练数据训练分类模型,并将其与格式相同的新数据一起使用。示例模型:vvmnnnkv/wine-quality
参数
名称 | 类型 |
---|---|
args | TabularClassificationArgs |
options? | Options |
返回值
Promise
\<TabularClassificationOutput
>
定义于
inference/src/tasks/tabular/tabularClassification.ts:24
tabularRegression
▸ tabularRegression(args
, options?
): Promise
\<TabularRegressionOutput
>
预测表格形式中给定特征集的目标值。通常,您需要使用您的训练数据训练回归模型,并将其用于格式相同的新数据。 示例模型:scikit-learn/Fish-Weight
参数
名称 | 类型 |
---|---|
args | TabularRegressionArgs |
options? | Options |
返回值
Promise
\<TabularRegressionOutput
>
定义于
inference/src/tasks/tabular/tabularRegression.ts:24
textClassification
▸ textClassification(args
, options?
): Promise
\<TextClassificationOutput
>
通常用于情感分析,这将输出输入类别的可能性。 推荐模型:distilbert-base-uncased-finetuned-sst-2-english
参数
名称 | 类型 |
---|---|
args | TextClassificationArgs |
options? | Options |
返回值
Promise
\<TextClassificationOutput
>
定义于
inference/src/tasks/nlp/textClassification.ts:11
textGeneration
▸ textGeneration(args
, options?
): Promise
\<TextGenerationOutput
>
用于从提示文本继续生成文本。 这是一个非常通用的任务。 推荐模型:gpt2(这是一个简单的模型,但玩起来很有趣)。
参数
名称 | 类型 |
---|---|
args | BaseArgs & TextGenerationInput |
options? | Options |
返回值
Promise
\<TextGenerationOutput
>
定义于
inference/src/tasks/nlp/textGeneration.ts:34
textGenerationStream
▸ textGenerationStream(args
, options?
): AsyncGenerator
\<TextGenerationStreamOutput
>
用于从提示词继续生成文本。与 textGeneration
相同,但返回可以一次读取一个 token 的生成器
参数
名称 | 类型 |
---|---|
args | BaseArgs & TextGenerationInput |
options? | Options |
返回值
AsyncGenerator
\<TextGenerationStreamOutput
>
定义于
inference/src/tasks/nlp/textGenerationStream.ts:88
textToImage
▸ textToImage(args
, options?
): Promise
\<string
>
此任务读取一些文本输入并输出图像。 推荐模型:stabilityai/stable-diffusion-2
参数
名称 | 类型 |
---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType : "url" } |
返回值
Promise
\<string
>
定义于
inference/src/tasks/cv/textToImage.ts:50
▸ textToImage(args
, options?
): Promise
\<Blob
>
参数
名称 | 类型 |
---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType? : "blob" } |
返回值
Promise
\<Blob
>
定义于
inference/src/tasks/cv/textToImage.ts:54
textToSpeech
▸ textToSpeech(args
, options?
): Promise
\<Blob
>
此任务合成发音给定文本的声音音频。 推荐模型:espnet/kan-bayashi_ljspeech_vits
参数
名称 | 类型 |
---|---|
args | TextToSpeechArgs |
options? | Options |
返回值
Promise
\<Blob
>
定义于
inference/src/tasks/audio/textToSpeech.ts:15
textToVideo
▸ textToVideo(args
, options?
): Promise
\<TextToVideoOutput
>
参数
名称 | 类型 |
---|---|
args | TextToVideoArgs |
options? | Options |
返回值
Promise
\<TextToVideoOutput
>
定义于
inference/src/tasks/cv/textToVideo.ts:26
词元分类
▸ 词元分类(args
, options?
): Promise
\<TokenClassificationOutput
>
通常用于句子解析,无论是语法解析还是命名实体识别 (NER),以理解文本中包含的关键词。推荐模型:dbmdz/bert-large-cased-finetuned-conll03-english
参数
名称 | 类型 |
---|---|
args | TokenClassificationArgs |
options? | Options |
返回值
Promise
\<TokenClassificationOutput
>
定义于
inference/src/tasks/nlp/tokenClassification.ts:12
翻译
▸ 翻译(args
, options?
): Promise
\<TranslationOutput
>
此任务广为人知,用于将文本从一种语言翻译成另一种语言。推荐模型:Helsinki-NLP/opus-mt-ru-en。
参数
名称 | 类型 |
---|---|
args | TranslationArgs |
options? | Options |
返回值
Promise
\<TranslationOutput
>
定义于
inference/src/tasks/nlp/translation.ts:10
视觉问答
▸ 视觉问答(args
, options?
): Promise
\<VisualQuestionAnsweringOutput
[number
]>
回答关于图像的问题。推荐模型:dandelin/vilt-b32-finetuned-vqa。
参数
名称 | 类型 |
---|---|
args | VisualQuestionAnsweringArgs |
options? | Options |
返回值
Promise
\<VisualQuestionAnsweringOutput
[number
]>
定义于
inference/src/tasks/multimodal/visualQuestionAnswering.ts:18
零样本分类
▸ 零样本分类(args
, options?
): Promise
\<ZeroShotClassificationOutput
>
此任务非常有用,可以尝试零代码分类,您只需传递一个句子/段落以及该句子的可能标签,即可获得结果。推荐模型:facebook/bart-large-mnli。
参数
名称 | 类型 |
---|---|
args | ZeroShotClassificationArgs |
options? | Options |
返回值
Promise
\<ZeroShotClassificationOutput
>
定义于
inference/src/tasks/nlp/zeroShotClassification.ts:12
零样本图像分类
▸ 零样本图像分类(args
, options?
): Promise
\<ZeroShotImageClassificationOutput
>
将图像分类到指定的类别。推荐模型:openai/clip-vit-large-patch14-336
参数
名称 | 类型 |
---|---|
args | ZeroShotImageClassificationArgs |
options? | Options |
返回值
Promise
\<ZeroShotImageClassificationOutput
>
定义于
inference/src/tasks/cv/zeroShotImageClassification.ts:43
< > 在 GitHub 上更新