Huggingface.js documentation
类:InferenceClient
类:InferenceClient
层级
Task↳
InferenceClient↳↳
HfInference
构造函数
constructor
• new InferenceClient(accessToken?, defaultOptions?): InferenceClient
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
accessToken | string | "" |
defaultOptions | Options & { endpointUrl?: string } | {} |
返回
定义于
inference/src/InferenceClient.ts:15
属性
accessToken
• Private Readonly accessToken:string
定义于
inference/src/InferenceClient.ts:12
defaultOptions
• Private Readonly defaultOptions: Options
定义于
inference/src/InferenceClient.ts:13
方法
audioClassification
▸ audioClassification(args, options?): Promise<AudioClassificationOutput>
此任务读取一些音频输入并输出各类别的似然值。 推荐模型:superb/hubert-large-superb-er
参数
| 名称 | 类型 |
|---|---|
args | AudioClassificationArgs |
options? | Options |
返回
Promise<AudioClassificationOutput>
定义于
inference/src/tasks/audio/audioClassification.ts:15
audioToAudio
▸ audioToAudio(args, options?): Promise<AudioToAudioOutput[]>
此任务读取一些音频输入并输出一个或多个音频文件。 示例模型:speechbrain/sepformer-wham 执行音频源分离。
参数
| 名称 | 类型 |
|---|---|
args | AudioToAudioArgs |
options? | Options |
返回
Promise<AudioToAudioOutput[]>
定义于
inference/src/tasks/audio/audioToAudio.ts:41
automaticSpeechRecognition
▸ automaticSpeechRecognition(args, options?): Promise<AutomaticSpeechRecognitionOutput>
此任务读取一些音频输入,并输出音频文件中所说的词语。 推荐模型(英语):facebook/wav2vec2-large-960h-lv60-self
参数
| 名称 | 类型 |
|---|---|
args | AutomaticSpeechRecognitionArgs |
options? | Options |
返回
Promise<AutomaticSpeechRecognitionOutput>
定义于
inference/src/tasks/audio/automaticSpeechRecognition.ts:13
chatCompletion
▸ chatCompletion(args, options?): Promise<ChatCompletionOutput>
使用聊天补全端点,通过 OpenAI 消息补全 API(无流式)生成对提示的响应
参数
| 名称 | 类型 |
|---|---|
args | BaseArgs & ChatCompletionInput |
options? | Options |
返回
Promise<ChatCompletionOutput>
定义于
inference/src/tasks/nlp/chatCompletion.ts:12
chatCompletionStream
▸ chatCompletionStream(args, options?): AsyncGenerator<ChatCompletionStreamOutput>
用于从提示词继续生成文本。与 textGeneration 相同,但返回一个生成器,可以逐个 token 读取。
参数
| 名称 | 类型 |
|---|---|
args | BaseArgs & ChatCompletionInput |
options? | Options |
返回
AsyncGenerator<ChatCompletionStreamOutput>
定义于
inference/src/tasks/nlp/chatCompletionStream.ts:12
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
endpoint
▸ endpoint(endpointUrl): InferenceClient
返回一个绑定到指定端点的新 InferenceClient 实例。
主要是为了向后兼容。
参数
| 名称 | 类型 |
|---|---|
endpointUrl | string |
返回
定义于
inference/src/InferenceClient.ts:46
featureExtraction
▸ featureExtraction(args, options?): Promise<FeatureExtractionOutput>
此任务读取一些文本并输出原始浮点值,这些值通常作为语义数据库/语义搜索的一部分被使用。
参数
| 名称 | 类型 |
|---|---|
args | FeatureExtractionArgs |
options? | Options |
返回
Promise<FeatureExtractionOutput>
定义于
inference/src/tasks/nlp/featureExtraction.ts:22
fillMask
▸ fillMask(args, options?): Promise<FillMaskOutput>
尝试用缺失的单词(准确地说是 token)来填补一个空缺。这是 BERT 模型的基础任务。
参数
| 名称 | 类型 |
|---|---|
args | FillMaskArgs |
options? | Options |
返回
Promise<FillMaskOutput>
定义于
inference/src/tasks/nlp/fillMask.ts:12
imageClassification
▸ imageClassification(args, options?): Promise<ImageClassificationOutput>
此任务读取一些图像输入并输出各类别的似然值。 推荐模型:google/vit-base-patch16-224
参数
| 名称 | 类型 |
|---|---|
args | ImageClassificationArgs |
options? | Options |
返回
Promise<ImageClassificationOutput>
定义于
inference/src/tasks/cv/imageClassification.ts:14
imageSegmentation
▸ imageSegmentation(args, options?): Promise<ImageSegmentationOutput>
该任务读取一些图像输入,并输出类别的可能性以及检测到的对象的边界框。 推荐模型:facebook/detr-resnet-50-panoptic
参数
| 名称 | 类型 |
|---|---|
args | ImageSegmentationArgs |
options? | Options |
返回
Promise<ImageSegmentationOutput>
定义于
inference/src/tasks/cv/imageSegmentation.ts:14
imageTextToImage
▸ imageTextToImage(args, options?): Promise<Blob>
该任务接收图像和文本输入,并输出新生成的图像。 推荐模型:black-forest-labs/FLUX.2-dev
参数
| 名称 | 类型 |
|---|---|
args | ImageTextToImageArgs |
options? | Options |
返回
Promise<Blob>
定义于
inference/src/tasks/cv/imageTextToImage.ts:13
imageTextToVideo
▸ imageTextToVideo(args, options?): Promise<Blob>
该任务接收图像和文本输入,并输出生成的视频。 推荐模型:Lightricks/LTX-Video
参数
| 名称 | 类型 |
|---|---|
args | ImageTextToVideoArgs |
options? | Options |
返回
Promise<Blob>
定义于
inference/src/tasks/cv/imageTextToVideo.ts:13
imageToImage
▸ imageToImage(args, options?): Promise<Blob>
此任务读取一些文本输入并输出图像。 推荐模型:lllyasviel/sd-controlnet-depth
参数
| 名称 | 类型 |
|---|---|
args | ImageToImageArgs |
options? | Options |
返回
Promise<Blob>
定义于
inference/src/tasks/cv/imageToImage.ts:14
imageToText
▸ imageToText(args, options?): Promise<ImageToTextOutput>
此任务读取一些图像输入并输出文本说明。
参数
| 名称 | 类型 |
|---|---|
args | ImageToTextArgs |
options? | Options |
返回
Promise<ImageToTextOutput>
定义于
inference/src/tasks/cv/imageToText.ts:12
imageToVideo
▸ imageToVideo(args, options?): Promise<Blob>
此任务读取一些文本输入并输出图像。 推荐模型:Wan-AI/Wan2.1-I2V-14B-720P
参数
| 名称 | 类型 |
|---|---|
args | ImageToVideoArgs |
options? | Options |
返回
Promise<Blob>
定义于
inference/src/tasks/cv/imageToVideo.ts:14
objectDetection
▸ objectDetection(args, options?): Promise<ObjectDetectionOutput>
此任务读取一些图像输入,并输出类别的可能性以及检测到的对象的边界框。 推荐模型:facebook/detr-resnet-50
参数
| 名称 | 类型 |
|---|---|
args | ObjectDetectionArgs |
options? | Options |
返回
Promise<ObjectDetectionOutput>
定义于
inference/src/tasks/cv/objectDetection.ts:14
questionAnswering
▸ questionAnswering(args, options?): Promise<QuestionAnsweringOutput[number]>
想要拥有一个能回答任何问题的全能机器人吗?推荐模型:deepset/roberta-base-squad2
参数
| 名称 | 类型 |
|---|---|
args | QuestionAnsweringArgs |
options? | Options |
返回
Promise<QuestionAnsweringOutput[number]>
定义于
inference/src/tasks/nlp/questionAnswering.ts:13
request
▸ request<T>(args, options?): Promise<T>
用于向推理提供商发起自定义调用的原语
类型参数
| 名称 |
|---|
T |
参数
| 名称 | 类型 |
|---|---|
args | RequestArgs |
options? | Options & { task?: InferenceTask } |
返回
Promise<T>
Deprecated
请改用特定的任务函数。此函数将在未来版本中移除。
定义于
inference/src/tasks/custom/request.ts:11
sentenceSimilarity
▸ sentenceSimilarity(args, options?): Promise<SentenceSimilarityOutput>
通过比较它们的嵌入,计算一段文本与一组其他句子之间的语义相似度。
参数
| 名称 | 类型 |
|---|---|
args | SentenceSimilarityArgs |
options? | Options |
返回
Promise<SentenceSimilarityOutput>
定义于
inference/src/tasks/nlp/sentenceSimilarity.ts:12
streamingRequest
▸ streamingRequest<T>(args, options?): AsyncGenerator<T>
…
类型参数
| 名称 |
|---|
T |
参数
| 名称 | 类型 |
|---|---|
args | RequestArgs |
options? | Options & { task?: InferenceTask } |
返回
AsyncGenerator<T>
Deprecated
请改用特定的任务函数。此函数将在未来版本中移除。
定义于
inference/src/tasks/custom/streamingRequest.ts:11
摘要
▸ 摘要(args, options?): Promise<SummarizationOutput>
该任务旨在将较长的文本概括为较短的文本。请注意,某些模型对输入长度有上限,这意味着摘要功能无法处理整本书等超长文本。选择模型时请务必留意这一点。
参数
| 名称 | 类型 |
|---|---|
args | SummarizationArgs |
options? | Options |
返回
Promise<SummarizationOutput>
定义于
inference/src/tasks/nlp/summarization.ts:12
tableQuestionAnswering
▸ 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:12
tabularClassification
▸ tabularClassification(args, options?): Promise<TabularClassificationOutput>
预测给定表格形式特征集的目标标签。 通常,您需要在训练数据上训练一个分类模型,并使用该模型处理具有相同格式的新数据。 示例模型:vvmnnnkv/wine-quality
参数
| 名称 | 类型 |
|---|---|
args | TabularClassificationArgs |
options? | Options |
返回
Promise<TabularClassificationOutput>
定义于
inference/src/tasks/tabular/tabularClassification.ts:25
tabularRegression
▸ tabularRegression(args, options?): Promise<TabularRegressionOutput>
预测给定表格形式特征集的目标值。 通常,您需要在训练数据上训练一个回归模型,并使用该模型处理具有相同格式的新数据。 示例模型:scikit-learn/Fish-Weight
参数
| 名称 | 类型 |
|---|---|
args | TabularRegressionArgs |
options? | Options |
返回
Promise<TabularRegressionOutput>
定义于
inference/src/tasks/tabular/tabularRegression.ts:25
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:12
textGeneration
▸ textGeneration(args, options?): Promise<TextGenerationOutput>
用于根据提示词继续生成文本。这是一个非常通用的任务。推荐模型:gpt2(它是一个简单的模型,但玩起来很有趣)。
参数
| 名称 | 类型 |
|---|---|
args | BaseArgs & TextGenerationInput |
options? | Options |
返回
Promise<TextGenerationOutput>
定义于
inference/src/tasks/nlp/textGeneration.ts:12
textGenerationStream
▸ textGenerationStream(args, options?): AsyncGenerator<TextGenerationStreamOutput>
用于从提示词继续生成文本。与 textGeneration 相同,但返回一个生成器,可以逐个 token 读取。
参数
| 名称 | 类型 |
|---|---|
args | BaseArgs & TextGenerationInput |
options? | Options |
返回
AsyncGenerator<TextGenerationStreamOutput>
定义于
inference/src/tasks/nlp/textGenerationStream.ts:90
textRanking
▸ textRanking(args, options?): Promise<TextRankingOutput>
使用重排序模型根据查询对文档的相关性进行排序。
参数
| 名称 | 类型 |
|---|---|
args | TextRankingArgs |
options? | Options |
返回
Promise<TextRankingOutput>
定义于
inference/src/tasks/nlp/textRanking.ts:12
textToAudio
▸ textToAudio(args, options?): Promise<Blob>
此任务根据输入的文本提示生成音频(例如音乐或音效)。 示例模型:stabilityai/stable-audio-open-1.0
参数
| 名称 | 类型 |
|---|---|
args | TextToAudioArgs |
options? | Options |
返回
Promise<Blob>
定义于
inference/src/tasks/audio/textToAudio.ts:18
textToImage
▸ textToImage(args, options?): Promise<string>
此任务读取一些文本输入并输出图像。 推荐模型:stabilityai/stable-diffusion-2
参数
| 名称 | 类型 |
|---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType: "url" } |
返回
Promise<string>
定义于
inference/src/tasks/cv/textToImage.ts:18
▸ textToImage(args, options?): Promise<string>
参数
| 名称 | 类型 |
|---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType: "dataUrl" } |
返回
Promise<string>
定义于
inference/src/tasks/cv/textToImage.ts:22
▸ textToImage(args, options?): Promise<Blob>
参数
| 名称 | 类型 |
|---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType?: "blob" } |
返回
Promise<Blob>
定义于
inference/src/tasks/cv/textToImage.ts:26
▸ textToImage(args, options?): Promise<Record<string, unknown>>
参数
| 名称 | 类型 |
|---|---|
args | TextToImageArgs |
options? | TextToImageOptions & { outputType?: "json" } |
返回
Promise<Record<string, unknown>>
定义于
inference/src/tasks/cv/textToImage.ts:30
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:15
tokenClassification
▸ tokenClassification(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
translation
▸ 翻译(args, options?): Promise<TranslationOutput>
该任务旨在将文本从一种语言翻译为另一种语言。推荐模型:Helsinki-NLP/opus-mt-ru-en。
参数
| 名称 | 类型 |
|---|---|
args | TranslationArgs |
options? | Options |
返回
Promise<TranslationOutput>
定义于
inference/src/tasks/nlp/translation.ts:11
visualQuestionAnswering
▸ visualQuestionAnswering(args, options?): Promise<VisualQuestionAnsweringOutput[number]>
回答图像上的问题。推荐模型:dandelin/vilt-b32-finetuned-vqa。
参数
| 名称 | 类型 |
|---|---|
args | VisualQuestionAnsweringArgs |
options? | Options |
返回
Promise<VisualQuestionAnsweringOutput[number]>
定义于
inference/src/tasks/multimodal/visualQuestionAnswering.ts:19
zeroShotClassification
▸ zeroShotClassification(args, options?): Promise<ZeroShotClassificationOutput>
该任务对于零代码尝试分类非常有用,您只需传入一个句子/段落及其可能的标签,即可获得结果。推荐模型:facebook/bart-large-mnli。
参数
| 名称 | 类型 |
|---|---|
args | ZeroShotClassificationArgs |
options? | Options |
返回
Promise<ZeroShotClassificationOutput>
定义于
inference/src/tasks/nlp/zeroShotClassification.ts:12
zeroShotImageClassification
▸ zeroShotImageClassification(args, options?): Promise<ZeroShotImageClassificationOutput>
将图像分类到指定的类别中。 推荐模型:openai/clip-vit-large-patch14-336
参数
| 名称 | 类型 |
|---|---|
args | ZeroShotImageClassificationArgs |
options? | Options |
返回
Promise<ZeroShotImageClassificationOutput>
定义于
inference/src/tasks/cv/zeroShotImageClassification.ts:44
Update on GitHub