The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community: Skip Login to HuggubgFaceHub when token is not set (#21561)
Miroslavaee55eda3932
diff --git a/libs/community/langchain_community/llms/huggingface_endpoint.py b/libs/community/langchain_community/llms/huggingface_endpoint.pyindex 31884057ff..2fe1bdc862 100644--- a/libs/community/langchain_community/llms/huggingface_endpoint.py+++ b/libs/community/langchain_community/llms/huggingface_endpoint.py@@ -1,5 +1,6 @@import jsonimport logging+import osfrom typing import Any, AsyncIterator, Dict, Iterator, List, Mapping, Optionalfrom langchain_core._api.deprecation import deprecated@@ -11,7 +12,6 @@ from langchain_core.language_models.llms import LLMfrom langchain_core.outputs import GenerationChunkfrom langchain_core.pydantic_v1 import Extra, Field, root_validatorfrom langchain_core.utils import (- get_from_dict_or_env,get_pydantic_field_names,pre_init,)@@ -177,16 +177,17 @@ class HuggingFaceEndpoint(LLM):"Could not import huggingface_hub python package. ""Please install it with `pip install huggingface_hub`.")- try:- huggingfacehub_api_token = get_from_dict_or_env(- values, "huggingfacehub_api_token", "HUGGINGFACEHUB_API_TOKEN"- )- login(token=huggingfacehub_api_token)- except Exception as e:- raise ValueError(- "Could not authenticate with huggingface_hub. "- "Please check your API token."- ) from e+ huggingfacehub_api_token = values["huggingfacehub_api_token"] or os.getenv(+ "HUGGINGFACEHUB_API_TOKEN"+ )+ if huggingfacehub_api_token is not None:+ try:+ login(token=huggingfacehub_api_token)+ except Exception as e:+ raise ValueError(+ "Could not authenticate with huggingface_hub. "+ "Please check your API token."+ ) from efrom huggingface_hub import AsyncInferenceClient, InferenceClient