From 465faab9355dfe1a21490560697538b5e15624b9 Mon Sep 17 00:00:00 2001 From: shibuiwilliam Date: Wed, 2 Aug 2023 01:09:09 +0900 Subject: [PATCH] fix apparent spelling inconsistencies (#8574) Use ImportErrors where appropriate --- libs/langchain/langchain/agents/agent_toolkits/csv/base.py | 2 +- .../langchain/agents/agent_toolkits/pandas/base.py | 4 ++-- .../langchain/langchain/agents/agent_toolkits/spark/base.py | 2 +- .../document_loaders/blob_loaders/youtube_audio.py | 2 +- libs/langchain/langchain/document_loaders/directory.py | 6 +++++- libs/langchain/langchain/document_loaders/evernote.py | 5 ++--- libs/langchain/langchain/document_loaders/geodataframe.py | 2 +- libs/langchain/langchain/document_loaders/parsers/audio.py | 4 ++-- libs/langchain/langchain/document_loaders/parsers/grobid.py | 6 +++++- .../langchain/document_loaders/parsers/html/bs4.py | 2 +- .../document_loaders/parsers/language/code_segmenter.py | 4 ++-- libs/langchain/langchain/document_loaders/parsers/pdf.py | 2 +- libs/langchain/langchain/document_loaders/reddit.py | 2 +- .../langchain/document_loaders/tencent_cos_directory.py | 2 +- .../langchain/document_loaders/tencent_cos_file.py | 2 +- libs/langchain/langchain/document_loaders/url.py | 2 +- libs/langchain/langchain/document_loaders/url_playwright.py | 2 +- libs/langchain/langchain/document_loaders/web_base.py | 2 +- .../document_transformers/embeddings_redundant_filter.py | 2 +- libs/langchain/langchain/document_transformers/html2text.py | 2 +- .../langchain/memory/chat_message_histories/cassandra.py | 2 +- .../langchain/memory/chat_message_histories/zep.py | 2 +- .../retrievers/document_compressors/chain_filter.py | 2 +- .../retrievers/document_compressors/cohere_rerank.py | 2 +- .../retrievers/document_compressors/embeddings_filter.py | 2 +- libs/langchain/langchain/tools/gmail/utils.py | 4 ++-- libs/langchain/langchain/tools/playwright/base.py | 2 +- .../langchain/tools/playwright/extract_hyperlinks.py | 2 +- .../langchain/tools/steamship_image_generation/utils.py | 2 +- libs/langchain/langchain/vectorstores/docarray/base.py | 4 ++-- 30 files changed, 44 insertions(+), 37 deletions(-) diff --git a/libs/langchain/langchain/agents/agent_toolkits/csv/base.py b/libs/langchain/langchain/agents/agent_toolkits/csv/base.py index 9cce0f2ba3..90aa8dd77a 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/csv/base.py +++ b/libs/langchain/langchain/agents/agent_toolkits/csv/base.py @@ -15,7 +15,7 @@ def create_csv_agent( try: import pandas as pd except ImportError: - raise ValueError( + raise ImportError( "pandas package not found, please install with `pip install pandas`" ) diff --git a/libs/langchain/langchain/agents/agent_toolkits/pandas/base.py b/libs/langchain/langchain/agents/agent_toolkits/pandas/base.py index 3c8a4615c0..f32015c469 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/pandas/base.py +++ b/libs/langchain/langchain/agents/agent_toolkits/pandas/base.py @@ -121,7 +121,7 @@ def _get_prompt_and_tools( pd.set_option("display.max_columns", None) except ImportError: - raise ValueError( + raise ImportError( "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) except ImportError: - raise ValueError( + raise ImportError( "pandas package not found, please install with `pip install pandas`" ) if input_variables is not None: diff --git a/libs/langchain/langchain/agents/agent_toolkits/spark/base.py b/libs/langchain/langchain/agents/agent_toolkits/spark/base.py index 2cecb0a6ac..6021432dae 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/spark/base.py +++ b/libs/langchain/langchain/agents/agent_toolkits/spark/base.py @@ -46,7 +46,7 @@ def create_spark_dataframe_agent( """Construct a Spark agent from an LLM and dataframe.""" 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: input_variables = ["df", "input", "agent_scratchpad"] diff --git a/libs/langchain/langchain/document_loaders/blob_loaders/youtube_audio.py b/libs/langchain/langchain/document_loaders/blob_loaders/youtube_audio.py index abfcc83362..6bb6119658 100644 --- a/libs/langchain/langchain/document_loaders/blob_loaders/youtube_audio.py +++ b/libs/langchain/langchain/document_loaders/blob_loaders/youtube_audio.py @@ -21,7 +21,7 @@ class YoutubeAudioLoader(BlobLoader): try: import yt_dlp except ImportError: - raise ValueError( + raise ImportError( "yt_dlp package not found, please install it with " "`pip install yt_dlp`" ) diff --git a/libs/langchain/langchain/document_loaders/directory.py b/libs/langchain/langchain/document_loaders/directory.py index 46bbf8e125..95bc963021 100644 --- a/libs/langchain/langchain/document_loaders/directory.py +++ b/libs/langchain/langchain/document_loaders/directory.py @@ -121,7 +121,11 @@ class DirectoryLoader(BaseLoader): if self.silent_errors: logger.warning(e) else: - raise e + raise ImportError( + "To log the progress of DirectoryLoader " + "you need to install tqdm, " + "`pip install tqdm`" + ) if self.use_multithreading: with concurrent.futures.ThreadPoolExecutor( diff --git a/libs/langchain/langchain/document_loaders/evernote.py b/libs/langchain/langchain/document_loaders/evernote.py index 49ba1c7eb0..d9765e55ca 100644 --- a/libs/langchain/langchain/document_loaders/evernote.py +++ b/libs/langchain/langchain/document_loaders/evernote.py @@ -74,12 +74,11 @@ class EverNoteLoader(BaseLoader): return html2text.html2text(content).strip() except ImportError as e: - logger.error( + raise ImportError( "Could not import `html2text`. Although it is not a required package " "to use Langchain, using the EverNote loader requires `html2text`. " "Please install `html2text` via `pip install html2text` and try again." - ) - raise e + ) from e @staticmethod def _parse_resource(resource: list) -> dict: diff --git a/libs/langchain/langchain/document_loaders/geodataframe.py b/libs/langchain/langchain/document_loaders/geodataframe.py index 95efeae724..68998212a1 100644 --- a/libs/langchain/langchain/document_loaders/geodataframe.py +++ b/libs/langchain/langchain/document_loaders/geodataframe.py @@ -20,7 +20,7 @@ class GeoDataFrameLoader(BaseLoader): try: import geopandas as gpd except ImportError: - raise ValueError( + raise ImportError( "geopandas package not found, please install it with " "`pip install geopandas`" ) diff --git a/libs/langchain/langchain/document_loaders/parsers/audio.py b/libs/langchain/langchain/document_loaders/parsers/audio.py index 81819544b4..126ba3f02d 100644 --- a/libs/langchain/langchain/document_loaders/parsers/audio.py +++ b/libs/langchain/langchain/document_loaders/parsers/audio.py @@ -21,14 +21,14 @@ class OpenAIWhisperParser(BaseBlobParser): try: import openai except ImportError: - raise ValueError( + raise ImportError( "openai package not found, please install it with " "`pip install openai`" ) try: from pydub import AudioSegment except ImportError: - raise ValueError( + raise ImportError( "pydub package not found, please install it with " "`pip install pydub`" ) diff --git a/libs/langchain/langchain/document_loaders/parsers/grobid.py b/libs/langchain/langchain/document_loaders/parsers/grobid.py index fd8c563d91..c19b21e23d 100644 --- a/libs/langchain/langchain/document_loaders/parsers/grobid.py +++ b/libs/langchain/langchain/document_loaders/parsers/grobid.py @@ -1,3 +1,4 @@ +import logging from typing import Dict, Iterator, List, Union import requests @@ -6,6 +7,8 @@ from langchain.docstore.document import Document from langchain.document_loaders.base import BaseBlobParser from langchain.document_loaders.blob_loaders import Blob +logger = logging.getLogger(__name__) + class ServerUnavailableException(Exception): """Exception raised when the GROBID server is unavailable.""" @@ -26,7 +29,7 @@ class GrobidParser(BaseBlobParser): try: requests.get(grobid_server) except requests.exceptions.RequestException: - print( + logger.error( "GROBID server does not appear up and running, \ please ensure Grobid is installed and the server is running" ) @@ -136,6 +139,7 @@ class GrobidParser(BaseBlobParser): ) xml_data = r.text except requests.exceptions.ReadTimeout: + logger.error("GROBID server timed out. Return None.") xml_data = None if xml_data is None: diff --git a/libs/langchain/langchain/document_loaders/parsers/html/bs4.py b/libs/langchain/langchain/document_loaders/parsers/html/bs4.py index 627bee5faf..e56aec31ab 100644 --- a/libs/langchain/langchain/document_loaders/parsers/html/bs4.py +++ b/libs/langchain/langchain/document_loaders/parsers/html/bs4.py @@ -24,7 +24,7 @@ class BS4HTMLParser(BaseBlobParser): try: import bs4 # noqa:F401 except ImportError: - raise ValueError( + raise ImportError( "beautifulsoup4 package not found, please install it with " "`pip install beautifulsoup4`" ) diff --git a/libs/langchain/langchain/document_loaders/parsers/language/code_segmenter.py b/libs/langchain/langchain/document_loaders/parsers/language/code_segmenter.py index 6264e40428..100fb78e81 100644 --- a/libs/langchain/langchain/document_loaders/parsers/language/code_segmenter.py +++ b/libs/langchain/langchain/document_loaders/parsers/language/code_segmenter.py @@ -13,8 +13,8 @@ class CodeSegmenter(ABC): @abstractmethod def simplify_code(self) -> str: - raise NotImplementedError # pragma: no cover + raise NotImplementedError() # pragma: no cover @abstractmethod def extract_functions_classes(self) -> List[str]: - raise NotImplementedError # pragma: no cover + raise NotImplementedError() # pragma: no cover diff --git a/libs/langchain/langchain/document_loaders/parsers/pdf.py b/libs/langchain/langchain/document_loaders/parsers/pdf.py index eb3c0d9d16..464a928e2b 100644 --- a/libs/langchain/langchain/document_loaders/parsers/pdf.py +++ b/libs/langchain/langchain/document_loaders/parsers/pdf.py @@ -87,7 +87,7 @@ class PyPDFium2Parser(BaseBlobParser): try: import pypdfium2 # noqa:F401 except ImportError: - raise ValueError( + raise ImportError( "pypdfium2 package not found, please install it with" " `pip install pypdfium2`" ) diff --git a/libs/langchain/langchain/document_loaders/reddit.py b/libs/langchain/langchain/document_loaders/reddit.py index 22fd112db1..44fa4bb811 100644 --- a/libs/langchain/langchain/document_loaders/reddit.py +++ b/libs/langchain/langchain/document_loaders/reddit.py @@ -14,7 +14,7 @@ def _dependable_praw_import() -> praw: try: import praw except ImportError: - raise ValueError( + raise ImportError( "praw package not found, please install it with `pip install praw`" ) return praw diff --git a/libs/langchain/langchain/document_loaders/tencent_cos_directory.py b/libs/langchain/langchain/document_loaders/tencent_cos_directory.py index 5b3a878536..14a249f8e1 100644 --- a/libs/langchain/langchain/document_loaders/tencent_cos_directory.py +++ b/libs/langchain/langchain/document_loaders/tencent_cos_directory.py @@ -27,7 +27,7 @@ class TencentCOSDirectoryLoader(BaseLoader): try: from qcloud_cos import CosS3Client except ImportError: - raise ValueError( + raise ImportError( "Could not import cos-python-sdk-v5 python package. " "Please install it with `pip install cos-python-sdk-v5`." ) diff --git a/libs/langchain/langchain/document_loaders/tencent_cos_file.py b/libs/langchain/langchain/document_loaders/tencent_cos_file.py index 8391ec54c8..4d96596716 100644 --- a/libs/langchain/langchain/document_loaders/tencent_cos_file.py +++ b/libs/langchain/langchain/document_loaders/tencent_cos_file.py @@ -29,7 +29,7 @@ class TencentCOSFileLoader(BaseLoader): try: from qcloud_cos import CosS3Client except ImportError: - raise ValueError( + raise ImportError( "Could not import cos-python-sdk-v5 python package. " "Please install it with `pip install cos-python-sdk-v5`." ) diff --git a/libs/langchain/langchain/document_loaders/url.py b/libs/langchain/langchain/document_loaders/url.py index de985d4741..013ec108f2 100644 --- a/libs/langchain/langchain/document_loaders/url.py +++ b/libs/langchain/langchain/document_loaders/url.py @@ -49,7 +49,7 @@ class UnstructuredURLLoader(BaseLoader): self.__version = __unstructured_version__ except ImportError: - raise ValueError( + raise ImportError( "unstructured package not found, please install it with " "`pip install unstructured`" ) diff --git a/libs/langchain/langchain/document_loaders/url_playwright.py b/libs/langchain/langchain/document_loaders/url_playwright.py index ad0d8f006c..ee4a47f251 100644 --- a/libs/langchain/langchain/document_loaders/url_playwright.py +++ b/libs/langchain/langchain/document_loaders/url_playwright.py @@ -38,7 +38,7 @@ class PlaywrightURLLoader(BaseLoader): try: import unstructured # noqa:F401 except ImportError: - raise ValueError( + raise ImportError( "unstructured package not found, please install it with " "`pip install unstructured`" ) diff --git a/libs/langchain/langchain/document_loaders/web_base.py b/libs/langchain/langchain/document_loaders/web_base.py index 3cac0cf962..ed684cd9ee 100644 --- a/libs/langchain/langchain/document_loaders/web_base.py +++ b/libs/langchain/langchain/document_loaders/web_base.py @@ -76,7 +76,7 @@ class WebBaseLoader(BaseLoader): try: import bs4 # noqa:F401 except ImportError: - raise ValueError( + raise ImportError( "bs4 package not found, please install it with " "`pip install bs4`" ) diff --git a/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py b/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py index ba57f2ef72..a108ce7300 100644 --- a/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py +++ b/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py @@ -83,7 +83,7 @@ def _filter_cluster_embeddings( try: from sklearn.cluster import KMeans except ImportError: - raise ValueError( + raise ImportError( "sklearn package not found, please install it with " "`pip install scikit-learn`" ) diff --git a/libs/langchain/langchain/document_transformers/html2text.py b/libs/langchain/langchain/document_transformers/html2text.py index d498f5505d..ede87af9c7 100644 --- a/libs/langchain/langchain/document_transformers/html2text.py +++ b/libs/langchain/langchain/document_transformers/html2text.py @@ -20,7 +20,7 @@ class Html2TextTransformer(BaseDocumentTransformer): try: import html2text except ImportError: - raise ValueError( + raise ImportError( """html2text package not found, please install it with `pip install html2text`""" ) diff --git a/libs/langchain/langchain/memory/chat_message_histories/cassandra.py b/libs/langchain/langchain/memory/chat_message_histories/cassandra.py index 6646e55ed2..2bf258e7be 100644 --- a/libs/langchain/langchain/memory/chat_message_histories/cassandra.py +++ b/libs/langchain/langchain/memory/chat_message_histories/cassandra.py @@ -41,7 +41,7 @@ class CassandraChatMessageHistory(BaseChatMessageHistory): try: from cassio.history import StoredBlobHistory except (ImportError, ModuleNotFoundError): - raise ValueError( + raise ImportError( "Could not import cassio python package. " "Please install it with `pip install cassio`." ) diff --git a/libs/langchain/langchain/memory/chat_message_histories/zep.py b/libs/langchain/langchain/memory/chat_message_histories/zep.py index 30983677bd..e349b438ab 100644 --- a/libs/langchain/langchain/memory/chat_message_histories/zep.py +++ b/libs/langchain/langchain/memory/chat_message_histories/zep.py @@ -61,7 +61,7 @@ class ZepChatMessageHistory(BaseChatMessageHistory): try: from zep_python import ZepClient except ImportError: - raise ValueError( + raise ImportError( "Could not import zep-python package. " "Please install it with `pip install zep-python`." ) diff --git a/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py b/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py index 68d6123a24..efe6886c88 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py +++ b/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py @@ -59,7 +59,7 @@ class LLMChainFilter(BaseDocumentCompressor): callbacks: Optional[Callbacks] = None, ) -> Sequence[Document]: """Filter down documents.""" - raise NotImplementedError + raise NotImplementedError() @classmethod def from_llm( diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 722cc6d33c..a9fad10c8b 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -90,4 +90,4 @@ class CohereRerank(BaseDocumentCompressor): query: str, callbacks: Optional[Callbacks] = None, ) -> Sequence[Document]: - raise NotImplementedError + raise NotImplementedError() diff --git a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py index fb49ca02ea..f004a17969 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py +++ b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py @@ -76,4 +76,4 @@ class EmbeddingsFilter(BaseDocumentCompressor): callbacks: Optional[Callbacks] = None, ) -> Sequence[Document]: """Filter down documents.""" - raise NotImplementedError + raise NotImplementedError() diff --git a/libs/langchain/langchain/tools/gmail/utils.py b/libs/langchain/langchain/tools/gmail/utils.py index d6e07445ba..ee562174c2 100644 --- a/libs/langchain/langchain/tools/gmail/utils.py +++ b/libs/langchain/langchain/tools/gmail/utils.py @@ -42,7 +42,7 @@ def import_installed_app_flow() -> InstalledAppFlow: try: from google_auth_oauthlib.flow import InstalledAppFlow except ImportError: - raise ValueError( + raise ImportError( "You need to install google-auth-oauthlib to use this toolkit. " "Try running pip install --upgrade google-auth-oauthlib" ) @@ -58,7 +58,7 @@ def import_googleapiclient_resource_builder() -> build_resource: try: from googleapiclient.discovery import build except ImportError: - raise ValueError( + raise ImportError( "You need to install googleapiclient to use this toolkit. " "Try running pip install --upgrade google-api-python-client" ) diff --git a/libs/langchain/langchain/tools/playwright/base.py b/libs/langchain/langchain/tools/playwright/base.py index 99f9e6cc58..7930a29fca 100644 --- a/libs/langchain/langchain/tools/playwright/base.py +++ b/libs/langchain/langchain/tools/playwright/base.py @@ -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.sync_api import Browser as SyncBrowser # noqa: F401 except ImportError: - raise ValueError( + raise ImportError( "The 'playwright' package is required to use the playwright tools." " Please install it with 'pip install playwright'." ) diff --git a/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py b/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py index 03902fa545..885059786a 100644 --- a/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py +++ b/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py @@ -38,7 +38,7 @@ class ExtractHyperlinksTool(BaseBrowserTool): try: from bs4 import BeautifulSoup # noqa: F401 except ImportError: - raise ValueError( + raise ImportError( "The 'beautifulsoup4' package is required to use this tool." " Please install it with 'pip install beautifulsoup4'." ) diff --git a/libs/langchain/langchain/tools/steamship_image_generation/utils.py b/libs/langchain/langchain/tools/steamship_image_generation/utils.py index 270a6e4b24..e89014e58c 100644 --- a/libs/langchain/langchain/tools/steamship_image_generation/utils.py +++ b/libs/langchain/langchain/tools/steamship_image_generation/utils.py @@ -14,7 +14,7 @@ def make_image_public(client: Steamship, block: Block) -> str: from steamship.data.workspace import SignedUrl from steamship.utils.signed_urls import upload_to_signed_url except ImportError: - raise ValueError( + raise ImportError( "The make_image_public function requires the steamship" " package to be installed. Please install steamship" " with `pip install --upgrade steamship`" diff --git a/libs/langchain/langchain/vectorstores/docarray/base.py b/libs/langchain/langchain/vectorstores/docarray/base.py index 18b4a01a35..fe58f49fcb 100644 --- a/libs/langchain/langchain/vectorstores/docarray/base.py +++ b/libs/langchain/langchain/vectorstores/docarray/base.py @@ -20,7 +20,7 @@ def _check_docarray_import() -> None: da_version = docarray.__version__.split(".") 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"version >=0.32.0 is expected, received: {docarray.__version__}." f"To upgrade, please run: `pip install -U docarray`." @@ -135,7 +135,7 @@ class DocArrayIndex(VectorStore, ABC): 0 is dissimilar, 1 is most similar. """ - raise NotImplementedError + raise NotImplementedError() def similarity_search_by_vector( self, embedding: List[float], k: int = 4, **kwargs: Any