From 4adb2b399da49f91be8c1babcdc9e489afafc0be Mon Sep 17 00:00:00 2001 From: Aashish Saini <141953346+ShorthillsAI@users.noreply.github.com> Date: Wed, 4 Oct 2023 07:16:26 +0530 Subject: [PATCH] Fixed exception type in py files (#11322) I've refactored the code to ensure that ImportError is consistently handled. Instead of using ValueError as before, I've now followed the standard practice of raising ImportError along with clear and informative error messages. This change enhances the code's clarity and explicitly signifies that any problems are associated with module imports. --- libs/langchain/langchain/chains/llm_requests.py | 2 +- libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py | 2 +- libs/langchain/langchain/llms/huggingface_endpoint.py | 2 +- libs/langchain/langchain/llms/petals.py | 2 +- libs/langchain/langchain/retrievers/pinecone_hybrid_search.py | 2 +- libs/langchain/langchain/retrievers/zep.py | 2 +- libs/langchain/langchain/utilities/apify.py | 2 +- libs/langchain/langchain/vectorstores/marqo.py | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/langchain/langchain/chains/llm_requests.py b/libs/langchain/langchain/chains/llm_requests.py index 8344c75958..95028d69e6 100644 --- a/libs/langchain/langchain/chains/llm_requests.py +++ b/libs/langchain/langchain/chains/llm_requests.py @@ -56,7 +56,7 @@ class LLMRequestsChain(Chain): from bs4 import BeautifulSoup # noqa: F401 except ImportError: - raise ValueError( + raise ImportError( "Could not import bs4 python package. " "Please install it with `pip install bs4`." ) diff --git a/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py b/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py index cb3fca33e9..cd5c6990c6 100644 --- a/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py +++ b/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py @@ -90,7 +90,7 @@ class QianfanEmbeddingsEndpoint(BaseModel, Embeddings): params["endpoint"] = values["endpoint"] values["client"] = qianfan.Embedding(**params) except ImportError: - raise ValueError( + raise ImportError( "qianfan package not found, please install it with " "`pip install qianfan`" ) diff --git a/libs/langchain/langchain/llms/huggingface_endpoint.py b/libs/langchain/langchain/llms/huggingface_endpoint.py index 2c55bb213e..850e3d465c 100644 --- a/libs/langchain/langchain/llms/huggingface_endpoint.py +++ b/libs/langchain/langchain/llms/huggingface_endpoint.py @@ -69,7 +69,7 @@ class HuggingFaceEndpoint(LLM): ) from e except ImportError: - raise ValueError( + raise ImportError( "Could not import huggingface_hub python package. " "Please install it with `pip install huggingface_hub`." ) diff --git a/libs/langchain/langchain/llms/petals.py b/libs/langchain/langchain/llms/petals.py index 9499b60288..1069d6a79a 100644 --- a/libs/langchain/langchain/llms/petals.py +++ b/libs/langchain/langchain/llms/petals.py @@ -103,7 +103,7 @@ class Petals(LLM): values["huggingface_api_key"] = huggingface_api_key except ImportError: - raise ValueError( + raise ImportError( "Could not import transformers or petals python package." "Please install with `pip install -U transformers petals`." ) diff --git a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py index 7b41616fef..98563ed8a6 100644 --- a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py +++ b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py @@ -144,7 +144,7 @@ class PineconeHybridSearchRetriever(BaseRetriever): BaseSparseEncoder, # noqa:F401 ) except ImportError: - raise ValueError( + raise ImportError( "Could not import pinecone_text python package. " "Please install it with `pip install pinecone_text`." ) diff --git a/libs/langchain/langchain/retrievers/zep.py b/libs/langchain/langchain/retrievers/zep.py index dafb28c824..39dd855636 100644 --- a/libs/langchain/langchain/retrievers/zep.py +++ b/libs/langchain/langchain/retrievers/zep.py @@ -41,7 +41,7 @@ class ZepRetriever(BaseRetriever): try: from zep_python import ZepClient except ImportError: - raise ValueError( + raise ImportError( "Could not import zep-python package. " "Please install it with `pip install zep-python`." ) diff --git a/libs/langchain/langchain/utilities/apify.py b/libs/langchain/langchain/utilities/apify.py index e10e96a1e5..b3a835457a 100644 --- a/libs/langchain/langchain/utilities/apify.py +++ b/libs/langchain/langchain/utilities/apify.py @@ -34,7 +34,7 @@ class ApifyWrapper(BaseModel): values["apify_client"] = ApifyClient(apify_api_token) values["apify_client_async"] = ApifyClientAsync(apify_api_token) except ImportError: - raise ValueError( + raise ImportError( "Could not import apify-client Python package. " "Please install it with `pip install apify-client`." ) diff --git a/libs/langchain/langchain/vectorstores/marqo.py b/libs/langchain/langchain/vectorstores/marqo.py index 261e14fd08..49b1d19aa6 100644 --- a/libs/langchain/langchain/vectorstores/marqo.py +++ b/libs/langchain/langchain/vectorstores/marqo.py @@ -61,7 +61,7 @@ class Marqo(VectorStore): try: import marqo except ImportError: - raise ValueError( + raise ImportError( "Could not import marqo python package. " "Please install it with `pip install marqo`." ) @@ -424,7 +424,7 @@ class Marqo(VectorStore): try: import marqo except ImportError: - raise ValueError( + raise ImportError( "Could not import marqo python package. " "Please install it with `pip install marqo`." )