mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-10 23:15:23 +00:00
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:
parent
c6d7124675
commit
4adb2b399d
@ -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`."
|
||||
)
|
||||
|
@ -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`"
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
@ -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`."
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user