mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-11 15:35:09 +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
|
from bs4 import BeautifulSoup # noqa: F401
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import bs4 python package. "
|
"Could not import bs4 python package. "
|
||||||
"Please install it with `pip install bs4`."
|
"Please install it with `pip install bs4`."
|
||||||
)
|
)
|
||||||
|
@ -90,7 +90,7 @@ class QianfanEmbeddingsEndpoint(BaseModel, Embeddings):
|
|||||||
params["endpoint"] = values["endpoint"]
|
params["endpoint"] = values["endpoint"]
|
||||||
values["client"] = qianfan.Embedding(**params)
|
values["client"] = qianfan.Embedding(**params)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"qianfan package not found, please install it with "
|
"qianfan package not found, please install it with "
|
||||||
"`pip install qianfan`"
|
"`pip install qianfan`"
|
||||||
)
|
)
|
||||||
|
@ -69,7 +69,7 @@ class HuggingFaceEndpoint(LLM):
|
|||||||
) from e
|
) from e
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import huggingface_hub python package. "
|
"Could not import huggingface_hub python package. "
|
||||||
"Please install it with `pip install huggingface_hub`."
|
"Please install it with `pip install huggingface_hub`."
|
||||||
)
|
)
|
||||||
|
@ -103,7 +103,7 @@ class Petals(LLM):
|
|||||||
values["huggingface_api_key"] = huggingface_api_key
|
values["huggingface_api_key"] = huggingface_api_key
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import transformers or petals python package."
|
"Could not import transformers or petals python package."
|
||||||
"Please install with `pip install -U transformers petals`."
|
"Please install with `pip install -U transformers petals`."
|
||||||
)
|
)
|
||||||
|
@ -144,7 +144,7 @@ class PineconeHybridSearchRetriever(BaseRetriever):
|
|||||||
BaseSparseEncoder, # noqa:F401
|
BaseSparseEncoder, # noqa:F401
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import pinecone_text python package. "
|
"Could not import pinecone_text python package. "
|
||||||
"Please install it with `pip install pinecone_text`."
|
"Please install it with `pip install pinecone_text`."
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ class ZepRetriever(BaseRetriever):
|
|||||||
try:
|
try:
|
||||||
from zep_python import ZepClient
|
from zep_python import ZepClient
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import zep-python package. "
|
"Could not import zep-python package. "
|
||||||
"Please install it with `pip install zep-python`."
|
"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"] = ApifyClient(apify_api_token)
|
||||||
values["apify_client_async"] = ApifyClientAsync(apify_api_token)
|
values["apify_client_async"] = ApifyClientAsync(apify_api_token)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import apify-client Python package. "
|
"Could not import apify-client Python package. "
|
||||||
"Please install it with `pip install apify-client`."
|
"Please install it with `pip install apify-client`."
|
||||||
)
|
)
|
||||||
|
@ -61,7 +61,7 @@ class Marqo(VectorStore):
|
|||||||
try:
|
try:
|
||||||
import marqo
|
import marqo
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import marqo python package. "
|
"Could not import marqo python package. "
|
||||||
"Please install it with `pip install marqo`."
|
"Please install it with `pip install marqo`."
|
||||||
)
|
)
|
||||||
@ -424,7 +424,7 @@ class Marqo(VectorStore):
|
|||||||
try:
|
try:
|
||||||
import marqo
|
import marqo
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ValueError(
|
raise ImportError(
|
||||||
"Could not import marqo python package. "
|
"Could not import marqo python package. "
|
||||||
"Please install it with `pip install marqo`."
|
"Please install it with `pip install marqo`."
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user