Huggingface.js documentation

@huggingface/inference

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

@huggingface/inference

Classes

Interfaces

Type Aliases

AudioClassificationArgs

Ƭ AudioClassificationArgs: BaseArgs & AudioClassificationInput | LegacyAudioInput

Defined in

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


AudioToAudioArgs

Ƭ AudioToAudioArgs: BaseArgs & { inputs: Blob } | LegacyAudioInput

Defined in

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


AutomaticSpeechRecognitionArgs

Ƭ AutomaticSpeechRecognitionArgs: BaseArgs & AutomaticSpeechRecognitionInput | LegacyAudioInput

Defined in

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


DocumentQuestionAnsweringArgs

Ƭ DocumentQuestionAnsweringArgs: BaseArgs & DocumentQuestionAnsweringInput & { inputs: DocumentQuestionAnsweringInputData & { image: Blob } }

Defined in

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


FeatureExtractionArgs

Ƭ FeatureExtractionArgs: BaseArgs & { inputs: string | string[] }

Defined in

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


FeatureExtractionOutput

Ƭ FeatureExtractionOutput: (number | number[] | number[][])[]

Returned values are a multidimensional array of floats (dimension depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model’s README).

Defined in

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


FillMaskArgs

Ƭ FillMaskArgs: BaseArgs & FillMaskInput

Defined in

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


ImageClassificationArgs

Ƭ ImageClassificationArgs: BaseArgs & ImageClassificationInput | LegacyImageInput

Defined in

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


ImageSegmentationArgs

Ƭ ImageSegmentationArgs: BaseArgs & ImageSegmentationInput | LegacyImageInput

Defined in

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


ImageToImageArgs

Ƭ ImageToImageArgs: BaseArgs & ImageToImageInput

Defined in

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


ImageToTextArgs

Ƭ ImageToTextArgs: BaseArgs & ImageToTextInput | LegacyImageInput

Defined in

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


InferenceProvider

Ƭ InferenceProvider: typeof INFERENCE_PROVIDERS[number]

Defined in

inference/src/types.ts:49


InferenceTask

Ƭ InferenceTask: Exclude\<PipelineType, "other">

Defined in

inference/src/types.ts:46


ModelId

Ƭ ModelId: string

HF model id, like “meta-llama/Llama-3.3-70B-Instruct”

Defined in

inference/src/types.ts:7


ObjectDetectionArgs

Ƭ ObjectDetectionArgs: BaseArgs & ObjectDetectionInput | LegacyImageInput

Defined in

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


ProviderMapping

Ƭ ProviderMapping\<ProviderId>: Partial\<Record\<WidgetType, Partial\<Record\<ModelId, ProviderId>>>>

Type parameters

Name Type
ProviderId extends string

Defined in

inference/src/providers/types.ts:4


QuestionAnsweringArgs

Ƭ QuestionAnsweringArgs: BaseArgs & QuestionAnsweringInput

Defined in

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


RequestArgs

Ƭ RequestArgs: BaseArgs & { data: Blob | ArrayBuffer } | { inputs: unknown } | { prompt: string } | { audio_url: string } | ChatCompletionInput & { accessToken?: string ; parameters?: Record\<string, unknown> }

Defined in

inference/src/types.ts:86


SentenceSimilarityArgs

Ƭ SentenceSimilarityArgs: BaseArgs & SentenceSimilarityInput

Defined in

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


SummarizationArgs

Ƭ SummarizationArgs: BaseArgs & SummarizationInput

Defined in

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


TableQuestionAnsweringArgs

Ƭ TableQuestionAnsweringArgs: BaseArgs & TableQuestionAnsweringInput

Defined in

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


TabularClassificationArgs

Ƭ TabularClassificationArgs: BaseArgs & { inputs: { data: Record\<string, string[]> } }

Defined in

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


TabularClassificationOutput

Ƭ TabularClassificationOutput: number[]

A list of predicted labels for each row

Defined in

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


TabularRegressionArgs

Ƭ TabularRegressionArgs: BaseArgs & { inputs: { data: Record\<string, string[]> } }

Defined in

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


TabularRegressionOutput

Ƭ TabularRegressionOutput: number[]

a list of predicted values for each row

Defined in

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


TextClassificationArgs

Ƭ TextClassificationArgs: BaseArgs & TextClassificationInput

Defined in

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


TextGenerationStreamFinishReason

Ƭ TextGenerationStreamFinishReason: "length" | "eos_token" | "stop_sequence"

Defined in

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


TextToImageArgs

Ƭ TextToImageArgs: BaseArgs & TextToImageInput

Defined in

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


TextToVideoArgs

Ƭ TextToVideoArgs: BaseArgs & TextToVideoInput

Defined in

inference/src/tasks/cv/textToVideo.ts:9


TextToVideoOutput

Ƭ TextToVideoOutput: Blob

Defined in

inference/src/tasks/cv/textToVideo.ts:11


TokenClassificationArgs

Ƭ TokenClassificationArgs: BaseArgs & TokenClassificationInput

Defined in

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


TranslationArgs

Ƭ TranslationArgs: BaseArgs & TranslationInput

Defined in

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


VisualQuestionAnsweringArgs

Ƭ VisualQuestionAnsweringArgs: BaseArgs & VisualQuestionAnsweringInput & { inputs: VisualQuestionAnsweringInputData & { image: Blob } }

Defined in

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


ZeroShotClassificationArgs

Ƭ ZeroShotClassificationArgs: BaseArgs & ZeroShotClassificationInput

Defined in

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


ZeroShotImageClassificationArgs

Ƭ ZeroShotImageClassificationArgs: BaseArgs & ZeroShotImageClassificationInput | LegacyZeroShotImageClassificationInput

Defined in

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

Variables

FAL _ AI _ SUPPORTED _ MODEL _ IDS

Const FAL_AI_SUPPORTED_MODEL_IDS: ProviderMapping\<FalAiId>

Defined in

inference/src/providers/fal-ai.ts:7


INFERENCE _ PROVIDERS

Const INFERENCE_PROVIDERS: readonly ["fal-ai", "replicate", "sambanova", "together", "hf-inference"]

Defined in

inference/src/types.ts:48


REPLICATE _ SUPPORTED _ MODEL _ IDS

Const REPLICATE_SUPPORTED_MODEL_IDS: ProviderMapping\<ReplicateId>

Defined in

inference/src/providers/replicate.ts:7


SAMBANOVA _ SUPPORTED _ MODEL _ IDS

Const SAMBANOVA_SUPPORTED_MODEL_IDS: ProviderMapping\<SambanovaId>

Defined in

inference/src/providers/sambanova.ts:7


TOGETHER _ SUPPORTED _ MODEL _ IDS

Const TOGETHER_SUPPORTED_MODEL_IDS: ProviderMapping\<TogetherId>

https://docs.together.ai/reference/models-1

Defined in

inference/src/providers/together.ts:13

Functions

audioClassification

audioClassification(args, options?): Promise\<AudioClassificationOutput>

This task reads some audio input and outputs the likelihood of classes. Recommended model: superb/hubert-large-superb-er

Parameters

Name Type
args AudioClassificationArgs
options? Options

Returns

Promise\<AudioClassificationOutput>

Defined in

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


audioToAudio

audioToAudio(args, options?): Promise\<AudioToAudioOutput[]>

This task reads some audio input and outputs one or multiple audio files. Example model: speechbrain/sepformer-wham does audio source separation.

Parameters

Name Type
args AudioToAudioArgs
options? Options

Returns

Promise\<AudioToAudioOutput[]>

Defined in

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


automaticSpeechRecognition

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

This task reads some audio input and outputs the said words within the audio files. Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self

Parameters

Name Type
args AutomaticSpeechRecognitionArgs
options? Options

Returns

Promise\<AutomaticSpeechRecognitionOutput>

Defined in

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


chatCompletion

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

Use the chat completion endpoint to generate a response to a prompt, using OpenAI message completion API no stream

Parameters

Name Type
args BaseArgs & ChatCompletionInput
options? Options

Returns

Promise\<ChatCompletionOutput>

Defined in

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


chatCompletionStream

chatCompletionStream(args, options?): AsyncGenerator\<ChatCompletionStreamOutput>

Use to continue text from a prompt. Same as textGeneration but returns generator that can be read one token at a time

Parameters

Name Type
args BaseArgs & ChatCompletionInput
options? Options

Returns

AsyncGenerator\<ChatCompletionStreamOutput>

Defined in

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


documentQuestionAnswering

documentQuestionAnswering(args, options?): Promise\<DocumentQuestionAnsweringOutput[number]>

Answers a question on a document image. Recommended model: impira/layoutlm-document-qa.

Parameters

Name Type
args DocumentQuestionAnsweringArgs
options? Options

Returns

Promise\<DocumentQuestionAnsweringOutput[number]>

Defined in

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


featureExtraction

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

This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.

Parameters

Name Type
args FeatureExtractionArgs
options? Options

Returns

Promise\<FeatureExtractionOutput>

Defined in

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


fillMask

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

Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.

Parameters

Name Type
args FillMaskArgs
options? Options

Returns

Promise\<FillMaskOutput>

Defined in

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


imageClassification

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

This task reads some image input and outputs the likelihood of classes. Recommended model: google/vit-base-patch16-224

Parameters

Name Type
args ImageClassificationArgs
options? Options

Returns

Promise\<ImageClassificationOutput>

Defined in

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


imageSegmentation

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

This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects. Recommended model: facebook/detr-resnet-50-panoptic

Parameters

Name Type
args ImageSegmentationArgs
options? Options

Returns

Promise\<ImageSegmentationOutput>

Defined in

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


imageToImage

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

This task reads some text input and outputs an image. Recommended model: lllyasviel/sd-controlnet-depth

Parameters

Name Type
args ImageToImageArgs
options? Options

Returns

Promise\<Blob>

Defined in

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


imageToText

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

This task reads some image input and outputs the text caption.

Parameters

Name Type
args ImageToTextArgs
options? Options

Returns

Promise\<ImageToTextOutput>

Defined in

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


objectDetection

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

This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects. Recommended model: facebook/detr-resnet-50

Parameters

Name Type
args ObjectDetectionArgs
options? Options

Returns

Promise\<ObjectDetectionOutput>

Defined in

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


questionAnswering

questionAnswering(args, options?): Promise\<QuestionAnsweringOutput[number]>

Want to have a nice know-it-all bot that can answer any question?. Recommended model: deepset/roberta-base-squad2

Parameters

Name Type
args QuestionAnsweringArgs
options? Options

Returns

Promise\<QuestionAnsweringOutput[number]>

Defined in

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


request

request\<T>(args, options?): Promise\<T>

Primitive to make custom calls to the inference provider

Type parameters

Name
T

Parameters

Name Type
args RequestArgs
options? Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }

Returns

Promise\<T>

Defined in

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


sentenceSimilarity

sentenceSimilarity(args, options?): Promise\<SentenceSimilarityOutput>

Calculate the semantic similarity between one text and a list of other sentences by comparing their embeddings.

Parameters

Name Type
args SentenceSimilarityArgs
options? Options

Returns

Promise\<SentenceSimilarityOutput>

Defined in

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


streamingRequest

streamingRequest\<T>(args, options?): AsyncGenerator\<T>

Primitive to make custom inference calls that expect server-sent events, and returns the response through a generator

Type parameters

Name
T

Parameters

Name Type
args RequestArgs
options? Options & { chatCompletion?: boolean ; task?: string ; taskHint?: InferenceTask }

Returns

AsyncGenerator\<T>

Defined in

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


summarization

summarization(args, options?): Promise\<SummarizationOutput>

This task is well known to summarize longer text into shorter text. Be careful, some models have a maximum length of input. That means that the summary cannot handle full books for instance. Be careful when choosing your model.

Parameters

Name Type
args SummarizationArgs
options? Options

Returns

Promise\<SummarizationOutput>

Defined in

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


tableQuestionAnswering

tableQuestionAnswering(args, options?): Promise\<TableQuestionAnsweringOutput[number]>

Don’t know SQL? Don’t want to dive into a large spreadsheet? Ask questions in plain english! Recommended model: google/tapas-base-finetuned-wtq.

Parameters

Name Type
args TableQuestionAnsweringArgs
options? Options

Returns

Promise\<TableQuestionAnsweringOutput[number]>

Defined in

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


tabularClassification

tabularClassification(args, options?): Promise\<TabularClassificationOutput>

Predicts target label for a given set of features in tabular form. Typically, you will want to train a classification model on your training data and use it with your new data of the same format. Example model: vvmnnnkv/wine-quality

Parameters

Name Type
args TabularClassificationArgs
options? Options

Returns

Promise\<TabularClassificationOutput>

Defined in

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


tabularRegression

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

Predicts target value for a given set of features in tabular form. Typically, you will want to train a regression model on your training data and use it with your new data of the same format. Example model: scikit-learn/Fish-Weight

Parameters

Name Type
args TabularRegressionArgs
options? Options

Returns

Promise\<TabularRegressionOutput>

Defined in

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


textClassification

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

Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english

Parameters

Name Type
args TextClassificationArgs
options? Options

Returns

Promise\<TextClassificationOutput>

Defined in

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


textGeneration

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

Use to continue text from a prompt. This is a very generic task. Recommended model: gpt2 (it’s a simple model, but fun to play with).

Parameters

Name Type
args BaseArgs & TextGenerationInput
options? Options

Returns

Promise\<TextGenerationOutput>

Defined in

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


textGenerationStream

textGenerationStream(args, options?): AsyncGenerator\<TextGenerationStreamOutput>

Use to continue text from a prompt. Same as textGeneration but returns generator that can be read one token at a time

Parameters

Name Type
args BaseArgs & TextGenerationInput
options? Options

Returns

AsyncGenerator\<TextGenerationStreamOutput>

Defined in

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


textToImage

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

This task reads some text input and outputs an image. Recommended model: stabilityai/stable-diffusion-2

Parameters

Name Type
args TextToImageArgs
options? Options

Returns

Promise\<Blob>

Defined in

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


textToSpeech

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

This task synthesize an audio of a voice pronouncing a given text. Recommended model: espnet/kan-bayashi_ljspeech_vits

Parameters

Name Type
args TextToSpeechArgs
options? Options

Returns

Promise\<Blob>

Defined in

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


textToVideo

textToVideo(args, options?): Promise\<TextToVideoOutput>

Parameters

Name Type
args TextToVideoArgs
options? Options

Returns

Promise\<TextToVideoOutput>

Defined in

inference/src/tasks/cv/textToVideo.ts:25


tokenClassification

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

Usually used for sentence parsing, either grammatical, or Named Entity Recognition (NER) to understand keywords contained within text. Recommended model: dbmdz/bert-large-cased-finetuned-conll03-english

Parameters

Name Type
args TokenClassificationArgs
options? Options

Returns

Promise\<TokenClassificationOutput>

Defined in

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


translation

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

This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.

Parameters

Name Type
args TranslationArgs
options? Options

Returns

Promise\<TranslationOutput>

Defined in

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


visualQuestionAnswering

visualQuestionAnswering(args, options?): Promise\<VisualQuestionAnsweringOutput[number]>

Answers a question on an image. Recommended model: dandelin/vilt-b32-finetuned-vqa.

Parameters

Name Type
args VisualQuestionAnsweringArgs
options? Options

Returns

Promise\<VisualQuestionAnsweringOutput[number]>

Defined in

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


zeroShotClassification

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

This task is super useful to try out classification with zero code, you simply pass a sentence/paragraph and the possible labels for that sentence, and you get a result. Recommended model: facebook/bart-large-mnli.

Parameters

Name Type
args ZeroShotClassificationArgs
options? Options

Returns

Promise\<ZeroShotClassificationOutput>

Defined in

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


zeroShotImageClassification

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

Classify an image to specified classes. Recommended model: openai/clip-vit-large-patch14-336

Parameters

Name Type
args ZeroShotImageClassificationArgs
options? Options

Returns

Promise\<ZeroShotImageClassificationOutput>

Defined in

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

< > Update on GitHub