mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-12 12:59:07 +00:00
community[minor]: import fix (#20995)
Issue: When the third-party package is not installed, whenever we need to `pip install <package>` the ImportError is raised. But sometimes, the `ValueError` or `ModuleNotFoundError` is raised. It is bad for consistency. Change: replaced the `ValueError` or `ModuleNotFoundError` with `ImportError` when we raise an error with the `pip install <package>` message. Note: Ideally, we replace all `try: import... except... raise ... `with helper functions like `import_aim` or just use the existing [langchain_core.utils.utils.guard_import](https://api.python.langchain.com/en/latest/utils/langchain_core.utils.utils.guard_import.html#langchain_core.utils.utils.guard_import) But it would be much bigger refactoring. @baskaryan Please, advice on this.
This commit is contained in:
@@ -323,7 +323,7 @@ class UpstashRedisCache(BaseCache):
|
||||
try:
|
||||
from upstash_redis import Redis
|
||||
except ImportError:
|
||||
raise ValueError(
|
||||
raise ImportError(
|
||||
"Could not import upstash_redis python package. "
|
||||
"Please install it with `pip install upstash_redis`."
|
||||
)
|
||||
@@ -461,7 +461,7 @@ class RedisCache(_RedisCacheBase):
|
||||
try:
|
||||
from redis import Redis
|
||||
except ImportError:
|
||||
raise ValueError(
|
||||
raise ImportError(
|
||||
"Could not import `redis` python package. "
|
||||
"Please install it with `pip install redis`."
|
||||
)
|
||||
@@ -528,7 +528,7 @@ class AsyncRedisCache(_RedisCacheBase):
|
||||
try:
|
||||
from redis.asyncio import Redis
|
||||
except ImportError:
|
||||
raise ValueError(
|
||||
raise ImportError(
|
||||
"Could not import `redis.asyncio` python package. "
|
||||
"Please install it with `pip install redis`."
|
||||
)
|
||||
@@ -1069,7 +1069,7 @@ class CassandraCache(BaseCache):
|
||||
try:
|
||||
from cassio.table import ElasticCassandraTable
|
||||
except (ImportError, ModuleNotFoundError):
|
||||
raise ValueError(
|
||||
raise ImportError(
|
||||
"Could not import cassio python package. "
|
||||
"Please install it with `pip install cassio`."
|
||||
)
|
||||
@@ -1192,7 +1192,7 @@ class CassandraSemanticCache(BaseCache):
|
||||
try:
|
||||
from cassio.table import MetadataVectorCassandraTable
|
||||
except (ImportError, ModuleNotFoundError):
|
||||
raise ValueError(
|
||||
raise ImportError(
|
||||
"Could not import cassio python package. "
|
||||
"Please install it with `pip install cassio`."
|
||||
)
|
||||
|
Reference in New Issue
Block a user