Text generation
Generate a one-off completion or response from a Hugging Face-hosted language model.
AI Tools · Const
Hugging Face Transformers is represented in the Vercel AI SDK by the Hugging Face provider. Use its provider instance to create language models for text generation and streaming.
The Hugging Face provider connects AI SDK generation functions to models exposed through Hugging Face Inference Providers. Import the default provider instance, select a model by identifier, and pass that model to functions such as generateText or streamText. A separately configured provider can be created when a custom API key is needed.
huggingFace(modelId)| Name | Type | Description |
|---|---|---|
modelId | string | The Hugging Face model identifier, such as meta-llama/Llama-3.1-8B-Instruct. |
A language model instance usable with AI SDK generation functions.
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
const { text } = await generateText({
model: huggingFace('meta-llama/Llama-3.1-8B-Instruct'),
prompt: 'Explain embeddings in one sentence.',
});
console.log(text);Generates text with a Hugging Face model through the AI SDK.
Generate a one-off completion or response from a Hugging Face-hosted language model.
Deliver model output incrementally to a user interface.
Use a custom Hugging Face API key or provider configuration.
createHuggingFacegenerateTextstreamTextproviderOptions.huggingface