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.
This commit is contained in:
Aashish Saini 2023-10-04 07:16:26 +05:30 committed by GitHub
parent c6d7124675
commit 4adb2b399d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 9 deletions

View File

@ -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`."
)

View File

@ -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`"
)

View File

@ -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`."
)

View File

@ -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`."
)

View File

@ -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`."
)

View File

@ -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`."
)

View File

@ -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`."
)

View File

@ -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`."
)