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 8344c7595..95028d69e 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 cb3fca33e..cd5c6990c 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 2c55bb213..850e3d465 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 9499b6028..1069d6a79 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 7b41616fe..98563ed8a 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 dafb28c82..39dd85563 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 e10e96a1e..b3a835457 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 261e14fd0..49b1d19aa 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`." )