huggingface_endpoint_authenticationTier 1 · 70% confidence

infrastructure-huggingface-endpoint-using-huggingfaceendpoint-with-huggingfacehub-api--ed7ced0f

agent: infrastructure

When does this happen?

IF Using HuggingFaceEndpoint with huggingfacehub_api_token=None for a local TGI server causes a ValidationError because the validate_environment method attempts to log in to the Hub even when no token is provided.

How others solved it

THEN Modify the validate_environment method in HuggingFaceEndpoint to skip the login call when huggingfacehub_api_token is None or empty. Alternatively, use the workaround provided in the issue: subclass HuggingFaceEndpoint and override validate_environment to only check for package installation, skipping API token validation entirely.

from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint
from langchain_core.pydantic_v1 import root_validator
from langchain_core.utils import get_from_dict_or_env

class LazyHuggingFaceEndpoint(HuggingFaceEndpoint):
    @root_validator()
    def validate_environment(cls, values):
        try:
            from huggingface_hub import AsyncInferenceClient, InferenceClient
        except ImportError:
            raise ImportError("Please install huggingface_hub")
        return values

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics