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.
pull/21023/head
Leonid Ganeline 2 months ago committed by GitHub
parent 2ddac9a7c3
commit dc7c06bc07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -323,7 +323,7 @@ class UpstashRedisCache(BaseCache):
try: try:
from upstash_redis import Redis from upstash_redis import Redis
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import upstash_redis python package. " "Could not import upstash_redis python package. "
"Please install it with `pip install upstash_redis`." "Please install it with `pip install upstash_redis`."
) )
@ -461,7 +461,7 @@ class RedisCache(_RedisCacheBase):
try: try:
from redis import Redis from redis import Redis
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import `redis` python package. " "Could not import `redis` python package. "
"Please install it with `pip install redis`." "Please install it with `pip install redis`."
) )
@ -528,7 +528,7 @@ class AsyncRedisCache(_RedisCacheBase):
try: try:
from redis.asyncio import Redis from redis.asyncio import Redis
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import `redis.asyncio` python package. " "Could not import `redis.asyncio` python package. "
"Please install it with `pip install redis`." "Please install it with `pip install redis`."
) )
@ -1069,7 +1069,7 @@ class CassandraCache(BaseCache):
try: try:
from cassio.table import ElasticCassandraTable from cassio.table import ElasticCassandraTable
except (ImportError, ModuleNotFoundError): except (ImportError, ModuleNotFoundError):
raise ValueError( raise ImportError(
"Could not import cassio python package. " "Could not import cassio python package. "
"Please install it with `pip install cassio`." "Please install it with `pip install cassio`."
) )
@ -1192,7 +1192,7 @@ class CassandraSemanticCache(BaseCache):
try: try:
from cassio.table import MetadataVectorCassandraTable from cassio.table import MetadataVectorCassandraTable
except (ImportError, ModuleNotFoundError): except (ImportError, ModuleNotFoundError):
raise ValueError( raise ImportError(
"Could not import cassio python package. " "Could not import cassio python package. "
"Please install it with `pip install cassio`." "Please install it with `pip install cassio`."
) )

@ -25,7 +25,7 @@ class Neo4jChatMessageHistory(BaseChatMessageHistory):
try: try:
import neo4j import neo4j
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import neo4j python package. " "Could not import neo4j python package. "
"Please install it with `pip install neo4j`." "Please install it with `pip install neo4j`."
) )

@ -25,7 +25,7 @@ class XataChatMessageHistory(BaseChatMessageHistory):
try: try:
from xata.client import XataClient # noqa: F401 from xata.client import XataClient # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import xata python package. " "Could not import xata python package. "
"Please install it with `pip install xata`." "Please install it with `pip install xata`."
) )

@ -127,7 +127,7 @@ class ChatAnyscale(ChatOpenAI):
import openai import openai
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import openai python package. " "Could not import openai python package. "
"Please install it with `pip install openai`.", "Please install it with `pip install openai`.",
) from e ) from e

@ -164,7 +164,7 @@ class QianfanChatEndpoint(BaseChatModel):
values["client"] = qianfan.ChatCompletion(**params) values["client"] = qianfan.ChatCompletion(**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`"
) )

@ -89,7 +89,7 @@ class ChatEverlyAI(ChatOpenAI):
import openai import openai
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import openai python package. " "Could not import openai python package. "
"Please install it with `pip install openai`.", "Please install it with `pip install openai`.",
) from e ) from e

@ -227,7 +227,7 @@ class JinaChat(BaseChatModel):
import openai import openai
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import openai python package. " "Could not import openai python package. "
"Please install it with `pip install openai`." "Please install it with `pip install openai`."
) )

@ -94,7 +94,7 @@ class ChatKonko(ChatOpenAI):
import konko import konko
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import konko python package. " "Could not import konko python package. "
"Please install it with `pip install konko`." "Please install it with `pip install konko`."
) )

@ -150,7 +150,7 @@ class ChatMLX(BaseChatModel):
from mlx_lm.utils import generate_step from mlx_lm.utils import generate_step
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import mlx_lm python package. " "Could not import mlx_lm python package. "
"Please install it with `pip install mlx_lm`." "Please install it with `pip install mlx_lm`."
) )

@ -67,7 +67,7 @@ def _import_tiktoken() -> Any:
try: try:
import tiktoken import tiktoken
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import tiktoken python package. " "Could not import tiktoken python package. "
"This is needed in order to calculate get_token_ids. " "This is needed in order to calculate get_token_ids. "
"Please install it with `pip install tiktoken`." "Please install it with `pip install tiktoken`."

@ -176,7 +176,7 @@ class ChatYuan2(BaseChatModel):
import openai import openai
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import openai python package. " "Could not import openai python package. "
"Please install it with `pip install openai`." "Please install it with `pip install openai`."
) )

@ -38,7 +38,7 @@ class OpenVINOReranker(BaseDocumentCompressor):
try: try:
from optimum.intel.openvino import OVModelForSequenceClassification from optimum.intel.openvino import OVModelForSequenceClassification
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import optimum-intel python package. " "Could not import optimum-intel python package. "
"Please install it with: " "Please install it with: "
"pip install -U 'optimum[openvino,nncf]'" "pip install -U 'optimum[openvino,nncf]'"
@ -47,7 +47,7 @@ class OpenVINOReranker(BaseDocumentCompressor):
try: try:
from huggingface_hub import HfApi from huggingface_hub import HfApi
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import huggingface_hub python package. " "Could not import huggingface_hub python package. "
"Please install it with: " "Please install it with: "
"`pip install -U huggingface_hub`." "`pip install -U huggingface_hub`."

@ -54,7 +54,7 @@ class AthenaLoader(BaseLoader):
try: try:
import boto3 import boto3
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
@ -115,7 +115,7 @@ class AthenaLoader(BaseLoader):
try: try:
import pandas as pd import pandas as pd
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import pandas python package. " "Could not import pandas python package. "
"Please install it with `pip install pandas`." "Please install it with `pip install pandas`."
) )

@ -634,7 +634,7 @@ class AmazonTextractPDFLoader(BasePDFLoader):
try: try:
import textractcaller as tc # noqa: F401 import textractcaller as tc # noqa: F401
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import amazon-textract-caller python package. " "Could not import amazon-textract-caller python package. "
"Please install it with `pip install amazon-textract-caller`." "Please install it with `pip install amazon-textract-caller`."
) )
@ -662,7 +662,7 @@ class AmazonTextractPDFLoader(BasePDFLoader):
client = session.client("textract", **client_params) client = session.client("textract", **client_params)
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
@ -710,7 +710,7 @@ class AmazonTextractPDFLoader(BasePDFLoader):
from PIL import Image, ImageSequence from PIL import Image, ImageSequence
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import pypdf or Pilloe python package. " "Could not import pypdf or Pilloe python package. "
"Please install it with `pip install pypdf Pillow`." "Please install it with `pip install pypdf Pillow`."
) )

@ -48,7 +48,7 @@ class UnstructuredBaseLoader(BaseLoader, ABC):
try: try:
import unstructured # noqa:F401 import unstructured # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"unstructured package not found, please install it with " "unstructured package not found, please install it with "
"`pip install unstructured`" "`pip install unstructured`"
) )

@ -98,7 +98,7 @@ class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings):
nice=values["nice"], nice=values["nice"],
) )
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import aleph_alpha_client python package. " "Could not import aleph_alpha_client python package. "
"Please install it with `pip install aleph_alpha_client`." "Please install it with `pip install aleph_alpha_client`."
) )
@ -121,7 +121,7 @@ class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings):
SemanticRepresentation, SemanticRepresentation,
) )
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import aleph_alpha_client python package. " "Could not import aleph_alpha_client python package. "
"Please install it with `pip install aleph_alpha_client`." "Please install it with `pip install aleph_alpha_client`."
) )
@ -161,7 +161,7 @@ class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings):
SemanticRepresentation, SemanticRepresentation,
) )
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import aleph_alpha_client python package. " "Could not import aleph_alpha_client python package. "
"Please install it with `pip install aleph_alpha_client`." "Please install it with `pip install aleph_alpha_client`."
) )
@ -209,7 +209,7 @@ class AlephAlphaSymmetricSemanticEmbedding(AlephAlphaAsymmetricSemanticEmbedding
SemanticRepresentation, SemanticRepresentation,
) )
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import aleph_alpha_client python package. " "Could not import aleph_alpha_client python package. "
"Please install it with `pip install aleph_alpha_client`." "Please install it with `pip install aleph_alpha_client`."
) )

@ -99,7 +99,7 @@ class BedrockEmbeddings(BaseModel, Embeddings):
values["client"] = session.client("bedrock-runtime", **client_params) values["client"] = session.client("bedrock-runtime", **client_params)
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )

@ -77,7 +77,7 @@ class CohereEmbeddings(BaseModel, Embeddings):
client_name=client_name, client_name=client_name,
) )
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import cohere python package. " "Could not import cohere python package. "
"Please install it with `pip install cohere`." "Please install it with `pip install cohere`."
) )

@ -88,7 +88,7 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
values["client"] = Llama(model_path, embedding=True, **model_params) values["client"] = Llama(model_path, embedding=True, **model_params)
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import llama-cpp-python library. " "Could not import llama-cpp-python library. "
"Please install the llama-cpp-python library to " "Please install the llama-cpp-python library to "
"use this embedding model: pip install llama-cpp-python" "use this embedding model: pip install llama-cpp-python"

@ -143,7 +143,7 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
) )
except ImportError as ex: except ImportError as ex:
raise ModuleNotFoundError( raise ImportError(
"Could not import oci python package. " "Could not import oci python package. "
"Please make sure you have the oci package installed." "Please make sure you have the oci package installed."
) from ex ) from ex

@ -424,7 +424,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
try: try:
from transformers import AutoTokenizer from transformers import AutoTokenizer
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import transformers python package. " "Could not import transformers python package. "
"This is needed in order to for OpenAIEmbeddings without " "This is needed in order to for OpenAIEmbeddings without "
"`tiktoken`. Please install it with `pip install transformers`. " "`tiktoken`. Please install it with `pip install transformers`. "
@ -557,7 +557,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
try: try:
from transformers import AutoTokenizer from transformers import AutoTokenizer
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import transformers python package. " "Could not import transformers python package. "
"This is needed in order to for OpenAIEmbeddings without " "This is needed in order to for OpenAIEmbeddings without "
" `tiktoken`. Please install it with `pip install transformers`." " `tiktoken`. Please install it with `pip install transformers`."

@ -51,7 +51,7 @@ class OpenVINOEmbeddings(BaseModel, Embeddings):
try: try:
from optimum.intel.openvino import OVModelForFeatureExtraction from optimum.intel.openvino import OVModelForFeatureExtraction
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import optimum-intel python package. " "Could not import optimum-intel python package. "
"Please install it with: " "Please install it with: "
"pip install -U 'optimum[openvino,nncf]'" "pip install -U 'optimum[openvino,nncf]'"
@ -60,7 +60,7 @@ class OpenVINOEmbeddings(BaseModel, Embeddings):
try: try:
from huggingface_hub import HfApi from huggingface_hub import HfApi
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Could not import huggingface_hub python package. " "Could not import huggingface_hub python package. "
"Please install it with: " "Please install it with: "
"`pip install -U huggingface_hub`." "`pip install -U huggingface_hub`."

@ -76,7 +76,7 @@ class AGEGraph(GraphStore):
try: try:
import psycopg2 import psycopg2
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import psycopg2 python package. " "Could not import psycopg2 python package. "
"Please install it with `pip install psycopg2`." "Please install it with `pip install psycopg2`."
) )

@ -55,7 +55,7 @@ class GremlinGraph(GraphStore):
if sys.platform == "win32": if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Please install gremlin-python first: " "`pip3 install gremlinpython" "Please install gremlin-python first: " "`pip3 install gremlinpython"
) )

@ -28,7 +28,7 @@ class HugeGraph:
try: try:
from hugegraph.connection import PyHugeGraph from hugegraph.connection import PyHugeGraph
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Please install HugeGraph Python client first: " "Please install HugeGraph Python client first: "
"`pip3 install hugegraph-python`" "`pip3 install hugegraph-python`"
) )

@ -47,7 +47,7 @@ class NebulaGraph:
import nebula3 # noqa: F401 import nebula3 # noqa: F401
import pandas # noqa: F401 import pandas # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Please install NebulaGraph Python client and pandas first: " "Please install NebulaGraph Python client and pandas first: "
"`pip install nebula3-python pandas`" "`pip install nebula3-python pandas`"
) )

@ -181,7 +181,7 @@ class Neo4jGraph(GraphStore):
try: try:
import neo4j import neo4j
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import neo4j python package. " "Could not import neo4j python package. "
"Please install it with `pip install neo4j`." "Please install it with `pip install neo4j`."
) )

@ -196,13 +196,13 @@ class NeptuneAnalyticsGraph(BaseNeptuneGraph):
self.client = session.client("neptune-graph") self.client = session.client("neptune-graph")
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
except Exception as e: except Exception as e:
if type(e).__name__ == "UnknownServiceError": if type(e).__name__ == "UnknownServiceError":
raise ModuleNotFoundError( raise ImportError(
"NeptuneGraph requires a boto3 version 1.34.40 or greater." "NeptuneGraph requires a boto3 version 1.34.40 or greater."
"Please install it with `pip install -U boto3`." "Please install it with `pip install -U boto3`."
) from e ) from e
@ -345,13 +345,13 @@ class NeptuneGraph(BaseNeptuneGraph):
) )
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
except Exception as e: except Exception as e:
if type(e).__name__ == "UnknownServiceError": if type(e).__name__ == "UnknownServiceError":
raise ModuleNotFoundError( raise ImportError(
"NeptuneGraph requires a boto3 version 1.28.38 or greater." "NeptuneGraph requires a boto3 version 1.28.38 or greater."
"Please install it with `pip install -U boto3`." "Please install it with `pip install -U boto3`."
) from e ) from e

@ -121,13 +121,13 @@ class NeptuneRdfGraph:
) )
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
except Exception as e: except Exception as e:
if type(e).__name__ == "UnknownServiceError": if type(e).__name__ == "UnknownServiceError":
raise ModuleNotFoundError( raise ImportError(
"NeptuneGraph requires a boto3 version 1.28.38 or greater." "NeptuneGraph requires a boto3 version 1.28.38 or greater."
"Please install it with `pip install -U boto3`." "Please install it with `pip install -U boto3`."
) from e ) from e

@ -81,7 +81,7 @@ class OntotextGraphDBGraph:
import rdflib import rdflib
from rdflib.plugins.stores import sparqlstore from rdflib.plugins.stores import sparqlstore
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import rdflib python package. " "Could not import rdflib python package. "
"Please install it with `pip install rdflib`." "Please install it with `pip install rdflib`."
) )

@ -146,7 +146,7 @@ class RdfGraph:
import rdflib import rdflib
from rdflib.plugins.stores import sparqlstore from rdflib.plugins.stores import sparqlstore
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import rdflib python package. " "Could not import rdflib python package. "
"Please install it with `pip install rdflib`." "Please install it with `pip install rdflib`."
) )

@ -424,7 +424,7 @@ class BedrockBase(BaseModel, ABC):
values["client"] = session.client("bedrock-runtime", **client_params) values["client"] = session.client("bedrock-runtime", **client_params)
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )

@ -53,7 +53,7 @@ class BigdlLLM(IpexLLM):
from transformers import AutoTokenizer, LlamaTokenizer from transformers import AutoTokenizer, LlamaTokenizer
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import bigdl-llm or transformers. " "Could not import bigdl-llm or transformers. "
"Please install it with `pip install --pre --upgrade bigdl-llm[all]`." "Please install it with `pip install --pre --upgrade bigdl-llm[all]`."
) )
@ -136,7 +136,7 @@ class BigdlLLM(IpexLLM):
from transformers import AutoTokenizer, LlamaTokenizer from transformers import AutoTokenizer, LlamaTokenizer
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import bigdl-llm or transformers. " "Could not import bigdl-llm or transformers. "
"Please install it with `pip install --pre --upgrade bigdl-llm[all]`." "Please install it with `pip install --pre --upgrade bigdl-llm[all]`."
) )

@ -88,7 +88,7 @@ class HuggingFaceHub(LLM):
) )
values["client"] = client values["client"] = client
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`."
) )

@ -92,7 +92,7 @@ class HuggingFacePipeline(BaseLLM):
from transformers import pipeline as hf_pipeline from transformers import pipeline as hf_pipeline
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import transformers python package. " "Could not import transformers python package. "
"Please install it with `pip install transformers`." "Please install it with `pip install transformers`."
) )
@ -107,7 +107,7 @@ class HuggingFacePipeline(BaseLLM):
from optimum.intel.openvino import OVModelForCausalLM from optimum.intel.openvino import OVModelForCausalLM
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import optimum-intel python package. " "Could not import optimum-intel python package. "
"Please install it with: " "Please install it with: "
"pip install 'optimum[openvino,nncf]' " "pip install 'optimum[openvino,nncf]' "
@ -133,7 +133,7 @@ class HuggingFacePipeline(BaseLLM):
from optimum.intel.openvino import OVModelForSeq2SeqLM from optimum.intel.openvino import OVModelForSeq2SeqLM
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import optimum-intel python package. " "Could not import optimum-intel python package. "
"Please install it with: " "Please install it with: "
"pip install 'optimum[openvino,nncf]' " "pip install 'optimum[openvino,nncf]' "
@ -159,7 +159,7 @@ class HuggingFacePipeline(BaseLLM):
f"currently only {VALID_TASKS} are supported" f"currently only {VALID_TASKS} are supported"
) )
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
f"Could not load the {task} model due to missing dependencies." f"Could not load the {task} model due to missing dependencies."
) from e ) from e

@ -132,7 +132,7 @@ class IpexLLM(LLM):
from transformers import AutoTokenizer, LlamaTokenizer from transformers import AutoTokenizer, LlamaTokenizer
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import ipex-llm. " "Could not import ipex-llm. "
"Please install `ipex-llm` properly following installation guides: " "Please install `ipex-llm` properly following installation guides: "
"https://github.com/intel-analytics/ipex-llm?tab=readme-ov-file#install-ipex-llm." "https://github.com/intel-analytics/ipex-llm?tab=readme-ov-file#install-ipex-llm."

@ -71,7 +71,7 @@ class Konko(LLM):
import konko import konko
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import konko python package. " "Could not import konko python package. "
"Please install it with `pip install konko`." "Please install it with `pip install konko`."
) )

@ -81,7 +81,7 @@ class MLXPipeline(LLM):
from mlx_lm import load from mlx_lm import load
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import mlx_lm python package. " "Could not import mlx_lm python package. "
"Please install it with `pip install mlx_lm`." "Please install it with `pip install mlx_lm`."
) )
@ -130,7 +130,7 @@ class MLXPipeline(LLM):
from mlx_lm import generate from mlx_lm import generate
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import mlx_lm python package. " "Could not import mlx_lm python package. "
"Please install it with `pip install mlx_lm`." "Please install it with `pip install mlx_lm`."
) )
@ -151,7 +151,7 @@ class MLXPipeline(LLM):
from mlx_lm.utils import generate_step from mlx_lm.utils import generate_step
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import mlx_lm python package. " "Could not import mlx_lm python package. "
"Please install it with `pip install mlx_lm`." "Please install it with `pip install mlx_lm`."
) )

@ -128,7 +128,7 @@ class OCIGenAIBase(BaseModel, ABC):
) )
except ImportError as ex: except ImportError as ex:
raise ModuleNotFoundError( raise ImportError(
"Could not import oci python package. " "Could not import oci python package. "
"Please make sure you have the oci package installed." "Please make sure you have the oci package installed."
) from ex ) from ex

@ -63,7 +63,7 @@ class SVEndpointHandler:
try: try:
import sseclient import sseclient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"could not import sseclient library" "could not import sseclient library"
"Please install it with `pip install sseclient-py`." "Please install it with `pip install sseclient-py`."
) )
@ -505,7 +505,7 @@ class SSEndpointHandler:
try: try:
import sseclient import sseclient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"could not import sseclient library" "could not import sseclient library"
"Please install it with `pip install sseclient-py`." "Please install it with `pip install sseclient-py`."
) )

@ -73,7 +73,7 @@ def _load_transformer(
f"currently only {VALID_TASKS} are supported" f"currently only {VALID_TASKS} are supported"
) )
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
f"Could not load the {task} model due to missing dependencies." f"Could not load the {task} model due to missing dependencies."
) from e ) from e

@ -108,7 +108,7 @@ class WeightOnlyQuantPipeline(LLM):
from transformers import AutoTokenizer from transformers import AutoTokenizer
from transformers import pipeline as hf_pipeline from transformers import pipeline as hf_pipeline
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import transformers python package. " "Could not import transformers python package. "
"Please install it with `pip install transformers` " "Please install it with `pip install transformers` "
"and `pip install intel-extension-for-transformers`." "and `pip install intel-extension-for-transformers`."
@ -154,7 +154,7 @@ class WeightOnlyQuantPipeline(LLM):
f"currently only {VALID_TASKS} are supported" f"currently only {VALID_TASKS} are supported"
) )
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
f"Could not load the {task} model due to missing dependencies." f"Could not load the {task} model due to missing dependencies."
) from e ) from e

@ -88,12 +88,12 @@ class AmazonKnowledgeBasesRetriever(BaseRetriever):
return values return values
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
except UnknownServiceError as e: except UnknownServiceError as e:
raise ModuleNotFoundError( raise ImportError(
"Ensure that you have installed the latest boto3 package " "Ensure that you have installed the latest boto3 package "
"that contains the API for `bedrock-runtime-agent`." "that contains the API for `bedrock-runtime-agent`."
) from e ) from e

@ -103,7 +103,7 @@ class ElasticSearchBM25Retriever(BaseRetriever):
try: try:
from elasticsearch.helpers import bulk from elasticsearch.helpers import bulk
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import elasticsearch python package. " "Could not import elasticsearch python package. "
"Please install it with `pip install elasticsearch`." "Please install it with `pip install elasticsearch`."
) )

@ -400,7 +400,7 @@ class AmazonKendraRetriever(BaseRetriever):
return values return values
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )

@ -36,7 +36,7 @@ class NeuralDBRetriever(BaseRetriever):
licensing.activate(thirdai_key or os.getenv("THIRDAI_KEY")) licensing.activate(thirdai_key or os.getenv("THIRDAI_KEY"))
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import thirdai python package and neuraldb dependencies. " "Could not import thirdai python package and neuraldb dependencies. "
"Please install it with `pip install thirdai[neural_db]`." "Please install it with `pip install thirdai[neural_db]`."
) )

@ -69,7 +69,7 @@ class SerpAPIWrapper(BaseModel):
values["search_engine"] = GoogleSearch values["search_engine"] = GoogleSearch
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import serpapi python package. " "Could not import serpapi python package. "
"Please install it with `pip install google-search-results`." "Please install it with `pip install google-search-results`."
) )

@ -82,7 +82,7 @@ class SparkSQL:
try: try:
from pyspark.sql import SparkSession from pyspark.sql import SparkSession
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pyspark is not installed. Please install it with `pip install pyspark`" "pyspark is not installed. Please install it with `pip install pyspark`"
) )

@ -189,7 +189,7 @@ class SQLDatabase:
try: try:
from databricks import sql # noqa: F401 from databricks import sql # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"databricks-sql-connector package not found, please install with" "databricks-sql-connector package not found, please install with"
" `pip install databricks-sql-connector`" " `pip install databricks-sql-connector`"
) )
@ -267,7 +267,7 @@ class SQLDatabase:
uri = make_cnosdb_langchain_uri(url, user, password, tenant, database) uri = make_cnosdb_langchain_uri(url, user, password, tenant, database)
return cls.from_uri(database_uri=uri) return cls.from_uri(database_uri=uri)
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"cnos-connector package not found, please install with" "cnos-connector package not found, please install with"
" `pip install cnos-connector`" " `pip install cnos-connector`"
) )

@ -149,7 +149,7 @@ class Chroma(VectorStore):
try: try:
import chromadb # noqa: F401 import chromadb # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import chromadb python package. " "Could not import chromadb python package. "
"Please install it with `pip install chromadb`." "Please install it with `pip install chromadb`."
) )

@ -51,7 +51,7 @@ class DashVector(VectorStore):
try: try:
import dashvector import dashvector
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import dashvector python package. " "Could not import dashvector python package. "
"Please install it with `pip install dashvector`." "Please install it with `pip install dashvector`."
) )
@ -366,7 +366,7 @@ class DashVector(VectorStore):
try: try:
import dashvector import dashvector
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import dashvector python package. " "Could not import dashvector python package. "
"Please install it with `pip install dashvector`." "Please install it with `pip install dashvector`."
) )

@ -913,7 +913,7 @@ class DeepLake(VectorStore):
try: try:
import deeplake import deeplake
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import deeplake python package. " "Could not import deeplake python package. "
"Please install it with `pip install deeplake`." "Please install it with `pip install deeplake`."
) )

@ -53,7 +53,7 @@ class Jaguar(VectorStore):
try: try:
from jaguardb_http_client.JaguarHttpClient import JaguarHttpClient from jaguardb_http_client.JaguarHttpClient import JaguarHttpClient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import jaguardb-http-client python package. " "Could not import jaguardb-http-client python package. "
"Please install it with `pip install -U jaguardb-http-client`" "Please install it with `pip install -U jaguardb-http-client`"
) )

@ -139,7 +139,7 @@ class Milvus(VectorStore):
try: try:
from pymilvus import Collection, utility from pymilvus import Collection, utility
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import pymilvus python package. " "Could not import pymilvus python package. "
"Please install it with `pip install pymilvus`." "Please install it with `pip install pymilvus`."
) )

@ -36,7 +36,7 @@ class NucliaDB(VectorStore):
try: try:
from nuclia.sdk import NucliaAuth from nuclia.sdk import NucliaAuth
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"nuclia python package not found. " "nuclia python package not found. "
"Please install it with `pip install nuclia`." "Please install it with `pip install nuclia`."
) )

@ -1625,7 +1625,7 @@ class Qdrant(VectorStore):
try: try:
import qdrant_client # noqa import qdrant_client # noqa
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import qdrant-client python package. " "Could not import qdrant-client python package. "
"Please install it with `pip install qdrant-client`." "Please install it with `pip install qdrant-client`."
) )
@ -1790,7 +1790,7 @@ class Qdrant(VectorStore):
try: try:
import qdrant_client # noqa import qdrant_client # noqa
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import qdrant-client python package. " "Could not import qdrant-client python package. "
"Please install it with `pip install qdrant-client`." "Please install it with `pip install qdrant-client`."
) )

@ -610,7 +610,7 @@ class Redis(VectorStore):
try: try:
import redis # noqa: F401 import redis # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import redis python package. " "Could not import redis python package. "
"Please install it with `pip install redis`." "Please install it with `pip install redis`."
) )
@ -651,7 +651,7 @@ class Redis(VectorStore):
try: try:
import redis # noqa: F401 import redis # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import redis python package. " "Could not import redis python package. "
"Please install it with `pip install redis`." "Please install it with `pip install redis`."
) )

@ -173,7 +173,7 @@ class Tair(VectorStore):
try: try:
from tair import tairvector from tair import tairvector
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import tair python package. " "Could not import tair python package. "
"Please install it with `pip install tair`." "Please install it with `pip install tair`."
) )
@ -262,7 +262,7 @@ class Tair(VectorStore):
try: try:
from tair import Tair as TairClient from tair import Tair as TairClient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import tair python package. " "Could not import tair python package. "
"Please install it with `pip install tair`." "Please install it with `pip install tair`."
) )

@ -47,7 +47,7 @@ class NeuralDBVectorStore(VectorStore):
licensing.activate(thirdai_key or os.getenv("THIRDAI_KEY")) licensing.activate(thirdai_key or os.getenv("THIRDAI_KEY"))
except ImportError: except ImportError:
raise ModuleNotFoundError( raise ImportError(
"Could not import thirdai python package and neuraldb dependencies. " "Could not import thirdai python package and neuraldb dependencies. "
"Please install it with `pip install thirdai[neural_db]`." "Please install it with `pip install thirdai[neural_db]`."
) )

@ -28,7 +28,7 @@ def dependable_tiledb_import() -> Any:
import tiledb as tiledb import tiledb as tiledb
import tiledb.vector_search as tiledb_vs import tiledb.vector_search as tiledb_vs
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import tiledb-vector-search python package. " "Could not import tiledb-vector-search python package. "
"Please install it with `conda install -c tiledb tiledb-vector-search` " "Please install it with `conda install -c tiledb tiledb-vector-search` "
"or `pip install tiledb-vector-search`" "or `pip install tiledb-vector-search`"

@ -227,7 +227,7 @@ class Typesense(VectorStore):
try: try:
from typesense import Client from typesense import Client
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import typesense python package. " "Could not import typesense python package. "
"Please install it with `pip install typesense`." "Please install it with `pip install typesense`."
) )

@ -58,7 +58,7 @@ class Vald(VectorStore):
try: try:
import grpc import grpc
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import grpcio python package. " "Could not import grpcio python package. "
"Please install it with `pip install grpcio`." "Please install it with `pip install grpcio`."
) )
@ -86,7 +86,7 @@ class Vald(VectorStore):
from vald.v1.payload import payload_pb2 from vald.v1.payload import payload_pb2
from vald.v1.vald import upsert_pb2_grpc from vald.v1.vald import upsert_pb2_grpc
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import vald-client-python python package. " "Could not import vald-client-python python package. "
"Please install it with `pip install vald-client-python`." "Please install it with `pip install vald-client-python`."
) )
@ -126,7 +126,7 @@ class Vald(VectorStore):
from vald.v1.payload import payload_pb2 from vald.v1.payload import payload_pb2
from vald.v1.vald import remove_pb2_grpc from vald.v1.vald import remove_pb2_grpc
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import vald-client-python python package. " "Could not import vald-client-python python package. "
"Please install it with `pip install vald-client-python`." "Please install it with `pip install vald-client-python`."
) )
@ -221,7 +221,7 @@ class Vald(VectorStore):
from vald.v1.payload import payload_pb2 from vald.v1.payload import payload_pb2
from vald.v1.vald import search_pb2_grpc from vald.v1.vald import search_pb2_grpc
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import vald-client-python python package. " "Could not import vald-client-python python package. "
"Please install it with `pip install vald-client-python`." "Please install it with `pip install vald-client-python`."
) )
@ -289,7 +289,7 @@ class Vald(VectorStore):
from vald.v1.payload import payload_pb2 from vald.v1.payload import payload_pb2
from vald.v1.vald import object_pb2_grpc from vald.v1.vald import object_pb2_grpc
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import vald-client-python python package. " "Could not import vald-client-python python package. "
"Please install it with `pip install vald-client-python`." "Please install it with `pip install vald-client-python`."
) )

@ -39,7 +39,7 @@ class Vearch(VectorStore):
else: else:
import vearch import vearch
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import suitable python package. " "Could not import suitable python package. "
"Please install it with `pip install vearch or vearch_cluster`." "Please install it with `pip install vearch or vearch_cluster`."
) )

@ -59,7 +59,7 @@ class VikingDB(VectorStore):
try: try:
from volcengine.viking_db import Collection, VikingDBService from volcengine.viking_db import Collection, VikingDBService
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import volcengine python package. " "Could not import volcengine python package. "
"Please install it with `pip install --upgrade volcengine`." "Please install it with `pip install --upgrade volcengine`."
) )
@ -104,7 +104,7 @@ class VikingDB(VectorStore):
try: try:
from volcengine.viking_db import Field, FieldType from volcengine.viking_db import Field, FieldType
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import volcengine python package. " "Could not import volcengine python package. "
"Please install it with `pip install --upgrade volcengine`." "Please install it with `pip install --upgrade volcengine`."
) )
@ -139,7 +139,7 @@ class VikingDB(VectorStore):
try: try:
from volcengine.viking_db import VectorIndexParams from volcengine.viking_db import VectorIndexParams
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import volcengine python package. " "Could not import volcengine python package. "
"Please install it with `pip install --upgrade volcengine`." "Please install it with `pip install --upgrade volcengine`."
) )
@ -177,7 +177,7 @@ class VikingDB(VectorStore):
try: try:
from volcengine.viking_db import Data from volcengine.viking_db import Data
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import volcengine python package. " "Could not import volcengine python package. "
"Please install it with `pip install --upgrade volcengine`." "Please install it with `pip install --upgrade volcengine`."
) )

@ -74,7 +74,7 @@ class TestLakeFSLoader(unittest.TestCase):
loader.set_repo(self.repo) loader.set_repo(self.repo)
loader.set_ref(self.ref) loader.set_ref(self.ref)
loader.set_path(self.path) loader.set_path(self.path)
with pytest.raises(ValueError): with pytest.raises(ImportError):
loader.load() loader.load()
@requests_mock.Mocker() @requests_mock.Mocker()

Loading…
Cancel
Save