docs[minor],community[patch]: Minor tutorial docs improvement, minor import error quick fix. (#22725)

minor changes to module import error handling and minor issues in
tutorial documents.

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
This commit is contained in:
Zheng Robert Jia
2024-06-20 14:36:49 -05:00
committed by GitHub
parent 7545b1d29b
commit a349fce880
5 changed files with 42 additions and 11 deletions

View File

@@ -89,7 +89,13 @@ class PyPDFParser(BaseBlobParser):
def lazy_parse(self, blob: Blob) -> Iterator[Document]: # type: ignore[valid-type]
"""Lazily parse the blob."""
import pypdf
try:
import pypdf
except ImportError:
raise ImportError(
"`pypdf` package not found, please install it with "
"`pip install pypdf`"
)
with blob.as_bytes_io() as pdf_file_obj: # type: ignore[attr-defined]
pdf_reader = pypdf.PdfReader(pdf_file_obj, password=self.password)
@@ -144,7 +150,13 @@ class PDFMinerParser(BaseBlobParser):
"""Lazily parse the blob."""
if not self.extract_images:
from pdfminer.high_level import extract_text
try:
from pdfminer.high_level import extract_text
except ImportError:
raise ImportError(
"`pdfminer` package not found, please install it with "
"`pip install pdfminer.six`"
)
with blob.as_bytes_io() as pdf_file_obj: # type: ignore[attr-defined]
if self.concatenate_pages: