fix exception inconsistencies (#8812) (#8839)

Merge #8812 with main to fix unrelated test failure

Co-authored-by: shibuiwilliam <shibuiyusuke@gmail.com>
This commit is contained in:
William FH 2023-08-06 14:04:49 -07:00 committed by GitHub
parent 15c271e7b3
commit f76d50d8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 10 deletions

View File

@ -43,7 +43,7 @@ class OBSDirectoryLoader(BaseLoader):
try: try:
from obs import ObsClient from obs import ObsClient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import esdk-obs-python python package. " "Could not import esdk-obs-python python package. "
"Please install it with `pip install esdk-obs-python`." "Please install it with `pip install esdk-obs-python`."
) )

View File

@ -67,7 +67,7 @@ class OBSFileLoader(BaseLoader):
try: try:
from obs import ObsClient from obs import ObsClient
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import esdk-obs-python python package. " "Could not import esdk-obs-python python package. "
"Please install it with `pip install esdk-obs-python`." "Please install it with `pip install esdk-obs-python`."
) )

View File

@ -149,14 +149,14 @@ class OpenAIWhisperParserLocal(BaseBlobParser):
try: try:
from pydub import AudioSegment from pydub import AudioSegment
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pydub package not found, please install it with " "`pip install pydub`" "pydub package not found, please install it with `pip install pydub`"
) )
try: try:
import librosa import librosa
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"librosa package not found, please install it with " "librosa package not found, please install it with "
"`pip install librosa`" "`pip install librosa`"
) )

View File

@ -183,7 +183,7 @@ class AmazonTextractPDFParser(BaseBlobParser):
else: else:
self.textract_features = [] self.textract_features = []
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`."
) )
@ -194,7 +194,7 @@ class AmazonTextractPDFParser(BaseBlobParser):
self.boto3_textract_client = boto3.client("textract") self.boto3_textract_client = boto3.client("textract")
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`."
) )

View File

@ -295,7 +295,13 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
if self.openai_api_type in ("azure", "azure_ad", "azuread"): if self.openai_api_type in ("azure", "azure_ad", "azuread"):
openai_args["engine"] = self.deployment openai_args["engine"] = self.deployment
if self.openai_proxy: if self.openai_proxy:
import openai try:
import openai
except ImportError:
raise ImportError(
"Could not import openai python package. "
"Please install it with `pip install openai`."
)
openai.proxy = { openai.proxy = {
"http": self.openai_proxy, "http": self.openai_proxy,

View File

@ -30,6 +30,7 @@ def _load_rapidfuzz() -> Any:
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Please install the rapidfuzz library to use the FuzzyMatchStringEvaluator." "Please install the rapidfuzz library to use the FuzzyMatchStringEvaluator."
"Please install it with `pip install rapidfuzz`."
) )
return rapidfuzz.distance return rapidfuzz.distance

View File

@ -66,6 +66,7 @@ class CosmosDBChatMessageHistory(BaseChatMessageHistory):
except ImportError as exc: except ImportError as exc:
raise ImportError( raise ImportError(
"You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501 "You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501
"Please install it with `pip install azure-cosmos`."
) from exc ) from exc
if self.credential: if self.credential:
self._client = CosmosClient( self._client = CosmosClient(
@ -94,6 +95,7 @@ class CosmosDBChatMessageHistory(BaseChatMessageHistory):
except ImportError as exc: except ImportError as exc:
raise ImportError( raise ImportError(
"You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501 "You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501
"Please install it with `pip install azure-cosmos`."
) from exc ) from exc
database = self._client.create_database_if_not_exists(self.cosmos_database) database = self._client.create_database_if_not_exists(self.cosmos_database)
self._container = database.create_container_if_not_exists( self._container = database.create_container_if_not_exists(
@ -130,6 +132,7 @@ class CosmosDBChatMessageHistory(BaseChatMessageHistory):
except ImportError as exc: except ImportError as exc:
raise ImportError( raise ImportError(
"You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501 "You must install the azure-cosmos package to use the CosmosDBChatMessageHistory." # noqa: E501
"Please install it with `pip install azure-cosmos`."
) from exc ) from exc
try: try:
item = self._container.read_item( item = self._container.read_item(

View File

@ -72,8 +72,9 @@ class NGramOverlapExampleSelector(BaseExampleSelector, BaseModel):
sentence_bleu, sentence_bleu,
) )
except ImportError as e: except ImportError as e:
raise ValueError( raise ImportError(
"Not all the correct dependencies for this ExampleSelect exist" "Not all the correct dependencies for this ExampleSelect exist."
"Please install nltk with `pip install nltk`."
) from e ) from e
return values return values