Skip to main content

Hugging Face

Bundles contain custom components that support specific third-party integrations with Langflow.

The components in the Hugging Face bundle require access to Hugging Face APIs.

For more information about Hugging Face features and functionality used by Hugging Face components, see the Hugging Face documentation.

Hugging Face text generation

The Hugging Face component generates text using a specified model by sending requests to the Hugging Face API, which is a hosted inference API for models hosted on Hugging Face. Authentication is required.

This component can output either a Model Response (Message) or a Language Model (LanguageModel). Specifically, the Language Model output is an instance of HuggingFaceHub configured according to the component's parameters.

Use the Language Model output when you want to use a Hugging Face model as the LLM for another LLM-driven component, such as a Language Model or Smart Function component.

For more information, see Language Model components.

Hugging Face text generation parameters

Many Hugging Face component input parameters are hidden by default in the visual editor. You can toggle parameters through the Controls in the component's header menu.

NameTypeDescription
model_idStringInput parameter. The model ID from Hugging Face Hub. For example, "gpt2", "facebook/bart-large".
huggingfacehub_api_tokenSecretStringInput parameter. Your Hugging Face API token for authentication.
temperatureFloatInput parameter. Controls randomness in the output. Range: [0.0, 1.0]. Default: 0.7.
max_new_tokensIntegerInput parameter. Maximum number of tokens to generate. Default: 512.
top_pFloatInput parameter. Nucleus sampling parameter. Range: [0.0, 1.0]. Default: 0.95.
top_kIntegerInput parameter. Top-k sampling parameter. Default: 50.
model_kwargsDictionaryInput parameter. Additional keyword arguments to pass to the model.

Hugging Face Embeddings Inference

Use the Hugging Face Embeddings Inference component to create embeddings with Hugging Face's hosted models or with your own locally hosted models.

The component generates embeddings using Hugging Face Inference API models. Authentication is required when not using a local model.

For more information about using embedding model components in flows, see Embedding Model components and Use a local Hugging Face embeddings model.

Hugging Face Embeddings Inference parameters

NameDisplay NameInfo
API KeyAPI KeyInput parameter. Your Hugging Face API token for accessing the Hugging Face Inference API, if required. Local inference models do not require an API key.
API URLAPI URLInput parameter. The URL of the Hugging Face Inference API.
Model NameModel NameInput parameter. The name of the model to use for embeddings.

Use a local Hugging Face embeddings model

To connect the local Hugging Face model to the Hugging Face Embeddings Inference component and use it in a flow, follow these steps:

  1. Run a local Hugging Face embeddings inference.

  2. For this example, create a flow from the Vector Store RAG template.

  3. Replace the two OpenAI Embeddings components with Hugging Face Embeddings Inference components.

    Make sure to reconnect the Embedding Model ports from each embedding model component to its corresponding Astra DB vector store component.

  4. Configure the Astra DB vector store components to connect to your Astra organization, or replace both Astra DB vector store components with other vector store components.

  5. Connect each Hugging Face Embeddings Inference component to your local inference model:

    • Inference Endpoint: Enter the URL of your local inference model.
    • API Key: Can be empty for local inference.
    • Model Name: Enter the name of your local inference model if it isn't automatically detected.
  6. To test the flow, click Playground, and then enter some text to generate an embedding.

Search