Class: HfInference

Constructors

constructor

new HfInference(apiKey?, defaultOptions?)

Parameters

Name Type Default value
apiKey string ""
defaultOptions Options {}

Defined in

HfInference.ts:597

Properties

apiKey

Private Readonly apiKey: string

Defined in

HfInference.ts:594


defaultOptions

Private Readonly defaultOptions: Options

Defined in

HfInference.ts:595

Methods

audioClassification

audioClassification(args, options?): Promise<AudioClassificationReturn>

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<AudioClassificationReturn>

Defined in

HfInference.ts:831


automaticSpeechRecognition

automaticSpeechRecognition(args, options?): Promise<AutomaticSpeechRecognitionReturn>

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<AutomaticSpeechRecognitionReturn>

Defined in

HfInference.ts:812


conversational

conversational(args, options?): Promise<ConversationalReturn>

This task corresponds to any chatbot like structure. Models tend to have shorter max_length, so please check with caution when using a given model if you need long range dependency or not. Recommended model: microsoft/DialoGPT-large.

Parameters

Name Type
args ConversationalArgs
options? Options

Returns

Promise<ConversationalReturn>

Defined in

HfInference.ts:782


featureExtraction

featureExtraction(args, options?): Promise<FeatureExtractionReturn>

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<FeatureExtractionReturn>

Defined in

HfInference.ts:803


fillMask

fillMask(args, options?): Promise<FillMaskReturn>

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<FillMaskReturn>

Defined in

HfInference.ts:605


imageClassification

imageClassification(args, options?): Promise<ImageClassificationReturn>

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<ImageClassificationReturn>

Defined in

HfInference.ts:851


imageSegmentation

imageSegmentation(args, options?): Promise<ImageSegmentationReturn>

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<ImageSegmentationReturn>

Defined in

HfInference.ts:899


makeRequestOptions

Private makeRequestOptions(args, options?): Object

Helper that prepares request arguments

Parameters

Name Type
args Args & { data?: ArrayBuffer | Blob ; stream?: boolean }
options? Options & { binary?: boolean ; blob?: boolean ; includeCredentials?: boolean }

Returns

Object

Name Type
info RequestInit
mergedOptions { binary?: boolean ; blob?: boolean ; dont_load_model?: boolean ; includeCredentials?: boolean ; retry_on_error?: boolean ; use_cache?: boolean ; use_gpu?: boolean ; wait_for_model?: boolean }
mergedOptions.binary? boolean
mergedOptions.blob? boolean
mergedOptions.dont_load_model? boolean
mergedOptions.includeCredentials? boolean
mergedOptions.retry_on_error? boolean
mergedOptions.use_cache? boolean
mergedOptions.use_gpu? boolean
mergedOptions.wait_for_model? boolean
url string

Defined in

HfInference.ts:934


objectDetection

objectDetection(args, options?): Promise<ObjectDetectionReturn>

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<ObjectDetectionReturn>

Defined in

HfInference.ts:871


questionAnswer

questionAnswer(args, options?): Promise<QuestionAnswerReturn>

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

Parameters

Name Type
args QuestionAnswerArgs
options? Options

Returns

Promise<QuestionAnswerReturn>

Defined in

HfInference.ts:639


request

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

Type parameters

Name
T

Parameters

Name Type
args Args & { data?: ArrayBuffer | Blob }
options? Options & { binary?: boolean ; blob?: boolean ; includeCredentials?: boolean }

Returns

Promise<T>

Defined in

HfInference.ts:986


streamingRequest

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

Make request that uses server-sent events and returns response as a generator

Type parameters

Name
T

Parameters

Name Type
args Args & { data?: ArrayBuffer | Blob }
options? Options & { binary?: boolean ; blob?: boolean ; includeCredentials?: boolean }

Returns

AsyncGenerator<T, any, unknown>

Defined in

HfInference.ts:1022


summarization

summarization(args, options?): Promise<SummarizationReturn>

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<SummarizationReturn>

Defined in

HfInference.ts:627


tableQuestionAnswer

tableQuestionAnswer(args, options?): Promise<TableQuestionAnswerReturn>

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 TableQuestionAnswerArgs
options? Options

Returns

Promise<TableQuestionAnswerReturn>

Defined in

HfInference.ts:657


textClassification

textClassification(args, options?): Promise<TextClassificationReturn>

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<TextClassificationReturn>

Defined in

HfInference.ts:680


textGeneration

textGeneration(args, options?): Promise<TextGenerationReturn>

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 TextGenerationArgs
options? Options

Returns

Promise<TextGenerationReturn>

Defined in

HfInference.ts:693


textGenerationStream

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

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 TextGenerationArgs
options? Options

Returns

AsyncGenerator<TextGenerationStreamReturn, any, unknown>

Defined in

HfInference.ts:705


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

HfInference.ts:919


tokenClassification

tokenClassification(args, options?): Promise<TokenClassificationReturn>

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<TokenClassificationReturn>

Defined in

HfInference.ts:715


translation

translation(args, options?): Promise<TranslationReturn>

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<TranslationReturn>

Defined in

HfInference.ts:741


zeroShotClassification

zeroShotClassification(args, options?): Promise<ZeroShotClassificationReturn>

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<ZeroShotClassificationReturn>

Defined in

HfInference.ts:753