From af94f1dd97295b2c15b3956ae1e0130f55607b1a Mon Sep 17 00:00:00 2001 From: Konstantin Hebenstreit <57603012+KonstantinHebenstreit@users.noreply.github.com> Date: Tue, 21 Feb 2023 06:09:39 +0100 Subject: [PATCH] HuggingFaceEndpoint: Correct Example for ImportError (#1176) When I try to import the Class HuggingFaceEndpoint I get an Import Error: cannot import name 'HuggingFaceEndpoint' from 'langchain'. (langchain version 0.0.88) These two imports work fine: from langchain import HuggingFacePipeline and from langchain import HuggingFaceHub. So I corrected the import statement in the example. There is probably a better solution to this, but this fixes the Error for me. --- langchain/__init__.py | 2 ++ langchain/llms/__init__.py | 3 +++ langchain/llms/huggingface_endpoint.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/langchain/__init__.py b/langchain/__init__.py index 6dd285ac..59a6cc54 100644 --- a/langchain/__init__.py +++ b/langchain/__init__.py @@ -28,6 +28,7 @@ from langchain.llms import ( Cohere, ForefrontAI, GooseAI, + HuggingFaceEndpoint, HuggingFaceHub, OpenAI, Petals, @@ -76,6 +77,7 @@ __all__ = [ "PromptTemplate", "ReActChain", "Wikipedia", + "HuggingFaceEndpoint", "HuggingFaceHub", "HuggingFacePipeline", "SQLDatabase", diff --git a/langchain/llms/__init__.py b/langchain/llms/__init__.py index 6ede7c3a..cc38b63d 100644 --- a/langchain/llms/__init__.py +++ b/langchain/llms/__init__.py @@ -8,6 +8,7 @@ from langchain.llms.cerebriumai import CerebriumAI from langchain.llms.cohere import Cohere from langchain.llms.forefrontai import ForefrontAI from langchain.llms.gooseai import GooseAI +from langchain.llms.huggingface_endpoint import HuggingFaceEndpoint from langchain.llms.huggingface_hub import HuggingFaceHub from langchain.llms.huggingface_pipeline import HuggingFacePipeline from langchain.llms.nlpcloud import NLPCloud @@ -26,6 +27,7 @@ __all__ = [ "NLPCloud", "OpenAI", "Petals", + "HuggingFaceEndpoint", "HuggingFaceHub", "HuggingFacePipeline", "AI21", @@ -43,6 +45,7 @@ type_to_cls_dict: Dict[str, Type[BaseLLM]] = { "forefrontai": ForefrontAI, "gooseai": GooseAI, "huggingface_hub": HuggingFaceHub, + "huggingface_endpoint": HuggingFaceEndpoint, "nlpcloud": NLPCloud, "openai": OpenAI, "petals": Petals, diff --git a/langchain/llms/huggingface_endpoint.py b/langchain/llms/huggingface_endpoint.py index dcc5e761..27799a3d 100644 --- a/langchain/llms/huggingface_endpoint.py +++ b/langchain/llms/huggingface_endpoint.py @@ -23,7 +23,7 @@ class HuggingFaceEndpoint(LLM, BaseModel): Example: .. code-block:: python - from langchain import HuggingFaceEndpoint + from langchain.llms.huggingface_endpoint import HuggingFaceEndpoint endpoint_url = ( "https://abcdefghijklmnop.us-east-1.aws.endpoints.huggingface.cloud" )