Skip to main content

Namespace: huggingface

Functions

Api

Api(settings): HuggingFaceApiConfiguration

Creates an API configuration for the HuggingFace API. It calls the API at https://api-inference.huggingface.co/models and uses the HUGGINGFACE_API_KEY env variable by default.

Parameters

NameType
settingsOmit<BaseUrlPartsApiConfigurationOptions, "baseUrl"> & { baseUrl?: string | Partial<UrlParts> } & { apiKey?: string }

Returns

HuggingFaceApiConfiguration

Defined in

packages/modelfusion/src/model-provider/huggingface/HuggingFaceFacade.ts:16


TextEmbedder

TextEmbedder(settings): HuggingFaceTextEmbeddingModel

Create a text embedding model that calls a Hugging Face Inference API Feature Extraction Task.

Parameters

NameType
settingsHuggingFaceTextEmbeddingModelSettings

Returns

HuggingFaceTextEmbeddingModel

A new instance of HuggingFaceTextEmbeddingModel.

See

https://huggingface.co/docs/api-inference/detailed_parameters#feature-extraction-task

Example

const model = huggingface.TextEmbedder({
model: "intfloat/e5-base-v2",
maxTexstsPerCall: 5,
retry: retryWithExponentialBackoff({ maxTries: 5 }),
});

const embeddings = await embedMany(
model,
[
"At first, Nox didn't know what to do with the pup.",
"He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
]
);

Defined in

packages/modelfusion/src/model-provider/huggingface/HuggingFaceFacade.ts:72


TextGenerator

TextGenerator(settings): HuggingFaceTextGenerationModel

Create a text generation model that calls a Hugging Face Inference API Text Generation Task.

Parameters

NameType
settingsHuggingFaceTextGenerationModelSettings

Returns

HuggingFaceTextGenerationModel

A new instance of HuggingFaceTextGenerationModel.

See

https://huggingface.co/docs/api-inference/detailed_parameters#text-generation-task

Example

const model = huggingface.TextGenerator({
model: "tiiuae/falcon-7b",
temperature: 0.7,
maxGenerationTokens: 500,
retry: retryWithExponentialBackoff({ maxTries: 5 }),
});

const text = await generateText(
model,
"Write a short story about a robot learning to love:\n\n"
);

Defined in

packages/modelfusion/src/model-provider/huggingface/HuggingFaceFacade.ts:44