Replaced instances of raising ValueError with raising ImportError. (#9388)

Refactored code to ensure consistent handling of ImportError. Replaced
instances of raising ValueError with raising ImportError.

The choice of raising a ValueError here is somewhat unconventional and
might lead to confusion for anyone reading the code. Typically, when
dealing with import-related errors, the recommended approach is to raise
an ImportError with a descriptive message explaining the issue. This
provides a clearer indication that the problem is related to importing
the required module.

@hwchase17 , @baskaryan , @eyurtsev 

Thanks
Aashish

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
pull/9419/head
Aashish Saini 11 months ago committed by GitHub
parent 0c4683ebcc
commit ce78877a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -149,7 +149,7 @@ class HuggingFaceInstructEmbeddings(BaseModel, Embeddings):
self.model_name, cache_folder=self.cache_folder, **self.model_kwargs
)
except ImportError as e:
raise ValueError("Dependencies for InstructorEmbedding not found.") from e
raise ImportError("Dependencies for InstructorEmbedding not found.") from e
class Config:
"""Configuration for this pydantic object."""

@ -30,7 +30,7 @@ class DuckDuckGoSearchAPIWrapper(BaseModel):
try:
from duckduckgo_search import DDGS # noqa: F401
except ImportError:
raise ValueError(
raise ImportError(
"Could not import duckduckgo-search python package. "
"Please install it with `pip install duckduckgo-search`."
)

Loading…
Cancel
Save