mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-29 09:58:44 +00:00
huggingface[patch]: Skip Login to HuggingFaceHub when token is not set (#22365)
This commit is contained in:
parent
f78ae1d932
commit
cbd5720011
@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from typing import Any, AsyncIterator, Dict, Iterator, List, Mapping, Optional
|
from typing import Any, AsyncIterator, Dict, Iterator, List, Mapping, Optional
|
||||||
|
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
@ -9,7 +10,7 @@ from langchain_core.callbacks import (
|
|||||||
from langchain_core.language_models.llms import LLM
|
from langchain_core.language_models.llms import LLM
|
||||||
from langchain_core.outputs import GenerationChunk
|
from langchain_core.outputs import GenerationChunk
|
||||||
from langchain_core.pydantic_v1 import Extra, Field, root_validator
|
from langchain_core.pydantic_v1 import Extra, Field, root_validator
|
||||||
from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names
|
from langchain_core.utils import get_pydantic_field_names
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -167,10 +168,11 @@ class HuggingFaceEndpoint(LLM):
|
|||||||
"Could not import huggingface_hub python package. "
|
"Could not import huggingface_hub python package. "
|
||||||
"Please install it with `pip install huggingface_hub`."
|
"Please install it with `pip install huggingface_hub`."
|
||||||
)
|
)
|
||||||
try:
|
huggingfacehub_api_token = values["huggingfacehub_api_token"] or os.getenv(
|
||||||
huggingfacehub_api_token = get_from_dict_or_env(
|
"HUGGINGFACEHUB_API_TOKEN"
|
||||||
values, "huggingfacehub_api_token", "HUGGINGFACEHUB_API_TOKEN"
|
|
||||||
)
|
)
|
||||||
|
if huggingfacehub_api_token is not None:
|
||||||
|
try:
|
||||||
login(token=huggingfacehub_api_token)
|
login(token=huggingfacehub_api_token)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
Loading…
Reference in New Issue
Block a user