fix apparent spelling inconsistencies (#8574)

Use ImportErrors where appropriate
This commit is contained in:
shibuiwilliam 2023-08-02 01:09:09 +09:00 committed by GitHub
parent 0ec020698f
commit 465faab935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 44 additions and 37 deletions

View File

@ -15,7 +15,7 @@ def create_csv_agent(
try: try:
import pandas as pd import pandas as pd
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pandas package not found, please install with `pip install pandas`" "pandas package not found, please install with `pip install pandas`"
) )

View File

@ -121,7 +121,7 @@ def _get_prompt_and_tools(
pd.set_option("display.max_columns", None) pd.set_option("display.max_columns", None)
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pandas package not found, please install with `pip install pandas`" "pandas package not found, please install with `pip install pandas`"
) )
@ -232,7 +232,7 @@ def _get_functions_prompt_and_tools(
pd.set_option("display.max_columns", None) pd.set_option("display.max_columns", None)
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pandas package not found, please install with `pip install pandas`" "pandas package not found, please install with `pip install pandas`"
) )
if input_variables is not None: if input_variables is not None:

View File

@ -46,7 +46,7 @@ def create_spark_dataframe_agent(
"""Construct a Spark agent from an LLM and dataframe.""" """Construct a Spark agent from an LLM and dataframe."""
if not _validate_spark_df(df) and not _validate_spark_connect_df(df): if not _validate_spark_df(df) and not _validate_spark_connect_df(df):
raise ValueError("Spark is not installed. run `pip install pyspark`.") raise ImportError("Spark is not installed. run `pip install pyspark`.")
if input_variables is None: if input_variables is None:
input_variables = ["df", "input", "agent_scratchpad"] input_variables = ["df", "input", "agent_scratchpad"]

View File

@ -21,7 +21,7 @@ class YoutubeAudioLoader(BlobLoader):
try: try:
import yt_dlp import yt_dlp
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"yt_dlp package not found, please install it with " "yt_dlp package not found, please install it with "
"`pip install yt_dlp`" "`pip install yt_dlp`"
) )

View File

@ -121,7 +121,11 @@ class DirectoryLoader(BaseLoader):
if self.silent_errors: if self.silent_errors:
logger.warning(e) logger.warning(e)
else: else:
raise e raise ImportError(
"To log the progress of DirectoryLoader "
"you need to install tqdm, "
"`pip install tqdm`"
)
if self.use_multithreading: if self.use_multithreading:
with concurrent.futures.ThreadPoolExecutor( with concurrent.futures.ThreadPoolExecutor(

View File

@ -74,12 +74,11 @@ class EverNoteLoader(BaseLoader):
return html2text.html2text(content).strip() return html2text.html2text(content).strip()
except ImportError as e: except ImportError as e:
logger.error( raise ImportError(
"Could not import `html2text`. Although it is not a required package " "Could not import `html2text`. Although it is not a required package "
"to use Langchain, using the EverNote loader requires `html2text`. " "to use Langchain, using the EverNote loader requires `html2text`. "
"Please install `html2text` via `pip install html2text` and try again." "Please install `html2text` via `pip install html2text` and try again."
) ) from e
raise e
@staticmethod @staticmethod
def _parse_resource(resource: list) -> dict: def _parse_resource(resource: list) -> dict:

View File

@ -20,7 +20,7 @@ class GeoDataFrameLoader(BaseLoader):
try: try:
import geopandas as gpd import geopandas as gpd
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"geopandas package not found, please install it with " "geopandas package not found, please install it with "
"`pip install geopandas`" "`pip install geopandas`"
) )

View File

@ -21,14 +21,14 @@ class OpenAIWhisperParser(BaseBlobParser):
try: try:
import openai import openai
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"openai package not found, please install it with " "openai package not found, please install it with "
"`pip install openai`" "`pip install openai`"
) )
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`"
) )

View File

@ -1,3 +1,4 @@
import logging
from typing import Dict, Iterator, List, Union from typing import Dict, Iterator, List, Union
import requests import requests
@ -6,6 +7,8 @@ from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseBlobParser from langchain.document_loaders.base import BaseBlobParser
from langchain.document_loaders.blob_loaders import Blob from langchain.document_loaders.blob_loaders import Blob
logger = logging.getLogger(__name__)
class ServerUnavailableException(Exception): class ServerUnavailableException(Exception):
"""Exception raised when the GROBID server is unavailable.""" """Exception raised when the GROBID server is unavailable."""
@ -26,7 +29,7 @@ class GrobidParser(BaseBlobParser):
try: try:
requests.get(grobid_server) requests.get(grobid_server)
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
print( logger.error(
"GROBID server does not appear up and running, \ "GROBID server does not appear up and running, \
please ensure Grobid is installed and the server is running" please ensure Grobid is installed and the server is running"
) )
@ -136,6 +139,7 @@ class GrobidParser(BaseBlobParser):
) )
xml_data = r.text xml_data = r.text
except requests.exceptions.ReadTimeout: except requests.exceptions.ReadTimeout:
logger.error("GROBID server timed out. Return None.")
xml_data = None xml_data = None
if xml_data is None: if xml_data is None:

View File

@ -24,7 +24,7 @@ class BS4HTMLParser(BaseBlobParser):
try: try:
import bs4 # noqa:F401 import bs4 # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"beautifulsoup4 package not found, please install it with " "beautifulsoup4 package not found, please install it with "
"`pip install beautifulsoup4`" "`pip install beautifulsoup4`"
) )

View File

@ -13,8 +13,8 @@ class CodeSegmenter(ABC):
@abstractmethod @abstractmethod
def simplify_code(self) -> str: def simplify_code(self) -> str:
raise NotImplementedError # pragma: no cover raise NotImplementedError() # pragma: no cover
@abstractmethod @abstractmethod
def extract_functions_classes(self) -> List[str]: def extract_functions_classes(self) -> List[str]:
raise NotImplementedError # pragma: no cover raise NotImplementedError() # pragma: no cover

View File

@ -87,7 +87,7 @@ class PyPDFium2Parser(BaseBlobParser):
try: try:
import pypdfium2 # noqa:F401 import pypdfium2 # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"pypdfium2 package not found, please install it with" "pypdfium2 package not found, please install it with"
" `pip install pypdfium2`" " `pip install pypdfium2`"
) )

View File

@ -14,7 +14,7 @@ def _dependable_praw_import() -> praw:
try: try:
import praw import praw
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"praw package not found, please install it with `pip install praw`" "praw package not found, please install it with `pip install praw`"
) )
return praw return praw

View File

@ -27,7 +27,7 @@ class TencentCOSDirectoryLoader(BaseLoader):
try: try:
from qcloud_cos import CosS3Client from qcloud_cos import CosS3Client
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import cos-python-sdk-v5 python package. " "Could not import cos-python-sdk-v5 python package. "
"Please install it with `pip install cos-python-sdk-v5`." "Please install it with `pip install cos-python-sdk-v5`."
) )

View File

@ -29,7 +29,7 @@ class TencentCOSFileLoader(BaseLoader):
try: try:
from qcloud_cos import CosS3Client from qcloud_cos import CosS3Client
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"Could not import cos-python-sdk-v5 python package. " "Could not import cos-python-sdk-v5 python package. "
"Please install it with `pip install cos-python-sdk-v5`." "Please install it with `pip install cos-python-sdk-v5`."
) )

View File

@ -49,7 +49,7 @@ class UnstructuredURLLoader(BaseLoader):
self.__version = __unstructured_version__ self.__version = __unstructured_version__
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`"
) )

View File

@ -38,7 +38,7 @@ class PlaywrightURLLoader(BaseLoader):
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`"
) )

View File

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

View File

@ -83,7 +83,7 @@ def _filter_cluster_embeddings(
try: try:
from sklearn.cluster import KMeans from sklearn.cluster import KMeans
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"sklearn package not found, please install it with " "sklearn package not found, please install it with "
"`pip install scikit-learn`" "`pip install scikit-learn`"
) )

View File

@ -20,7 +20,7 @@ class Html2TextTransformer(BaseDocumentTransformer):
try: try:
import html2text import html2text
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"""html2text package not found, please """html2text package not found, please
install it with `pip install html2text`""" install it with `pip install html2text`"""
) )

View File

@ -41,7 +41,7 @@ class CassandraChatMessageHistory(BaseChatMessageHistory):
try: try:
from cassio.history import StoredBlobHistory from cassio.history import StoredBlobHistory
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`."
) )

View File

@ -61,7 +61,7 @@ class ZepChatMessageHistory(BaseChatMessageHistory):
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`."
) )

View File

@ -59,7 +59,7 @@ class LLMChainFilter(BaseDocumentCompressor):
callbacks: Optional[Callbacks] = None, callbacks: Optional[Callbacks] = None,
) -> Sequence[Document]: ) -> Sequence[Document]:
"""Filter down documents.""" """Filter down documents."""
raise NotImplementedError raise NotImplementedError()
@classmethod @classmethod
def from_llm( def from_llm(

View File

@ -90,4 +90,4 @@ class CohereRerank(BaseDocumentCompressor):
query: str, query: str,
callbacks: Optional[Callbacks] = None, callbacks: Optional[Callbacks] = None,
) -> Sequence[Document]: ) -> Sequence[Document]:
raise NotImplementedError raise NotImplementedError()

View File

@ -76,4 +76,4 @@ class EmbeddingsFilter(BaseDocumentCompressor):
callbacks: Optional[Callbacks] = None, callbacks: Optional[Callbacks] = None,
) -> Sequence[Document]: ) -> Sequence[Document]:
"""Filter down documents.""" """Filter down documents."""
raise NotImplementedError raise NotImplementedError()

View File

@ -42,7 +42,7 @@ def import_installed_app_flow() -> InstalledAppFlow:
try: try:
from google_auth_oauthlib.flow import InstalledAppFlow from google_auth_oauthlib.flow import InstalledAppFlow
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"You need to install google-auth-oauthlib to use this toolkit. " "You need to install google-auth-oauthlib to use this toolkit. "
"Try running pip install --upgrade google-auth-oauthlib" "Try running pip install --upgrade google-auth-oauthlib"
) )
@ -58,7 +58,7 @@ def import_googleapiclient_resource_builder() -> build_resource:
try: try:
from googleapiclient.discovery import build from googleapiclient.discovery import build
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"You need to install googleapiclient to use this toolkit. " "You need to install googleapiclient to use this toolkit. "
"Try running pip install --upgrade google-api-python-client" "Try running pip install --upgrade google-api-python-client"
) )

View File

@ -30,7 +30,7 @@ def lazy_import_playwright_browsers() -> Tuple[Type[AsyncBrowser], Type[SyncBrow
from playwright.async_api import Browser as AsyncBrowser # noqa: F401 from playwright.async_api import Browser as AsyncBrowser # noqa: F401
from playwright.sync_api import Browser as SyncBrowser # noqa: F401 from playwright.sync_api import Browser as SyncBrowser # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"The 'playwright' package is required to use the playwright tools." "The 'playwright' package is required to use the playwright tools."
" Please install it with 'pip install playwright'." " Please install it with 'pip install playwright'."
) )

View File

@ -38,7 +38,7 @@ class ExtractHyperlinksTool(BaseBrowserTool):
try: try:
from bs4 import BeautifulSoup # noqa: F401 from bs4 import BeautifulSoup # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"The 'beautifulsoup4' package is required to use this tool." "The 'beautifulsoup4' package is required to use this tool."
" Please install it with 'pip install beautifulsoup4'." " Please install it with 'pip install beautifulsoup4'."
) )

View File

@ -14,7 +14,7 @@ def make_image_public(client: Steamship, block: Block) -> str:
from steamship.data.workspace import SignedUrl from steamship.data.workspace import SignedUrl
from steamship.utils.signed_urls import upload_to_signed_url from steamship.utils.signed_urls import upload_to_signed_url
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"The make_image_public function requires the steamship" "The make_image_public function requires the steamship"
" package to be installed. Please install steamship" " package to be installed. Please install steamship"
" with `pip install --upgrade steamship`" " with `pip install --upgrade steamship`"

View File

@ -20,7 +20,7 @@ def _check_docarray_import() -> None:
da_version = docarray.__version__.split(".") da_version = docarray.__version__.split(".")
if int(da_version[0]) == 0 and int(da_version[1]) <= 31: if int(da_version[0]) == 0 and int(da_version[1]) <= 31:
raise ValueError( raise ImportError(
f"To use the DocArrayHnswSearch VectorStore the docarray " f"To use the DocArrayHnswSearch VectorStore the docarray "
f"version >=0.32.0 is expected, received: {docarray.__version__}." f"version >=0.32.0 is expected, received: {docarray.__version__}."
f"To upgrade, please run: `pip install -U docarray`." f"To upgrade, please run: `pip install -U docarray`."
@ -135,7 +135,7 @@ class DocArrayIndex(VectorStore, ABC):
0 is dissimilar, 1 is most similar. 0 is dissimilar, 1 is most similar.
""" """
raise NotImplementedError raise NotImplementedError()
def similarity_search_by_vector( def similarity_search_by_vector(
self, embedding: List[float], k: int = 4, **kwargs: Any self, embedding: List[float], k: int = 4, **kwargs: Any