Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[minor]: Add aload to document loader #19936

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def lazy_load(self) -> Iterator[Document]:
metadata = _build_metadata(soup, path)
yield Document(page_content=text, metadata=metadata)

def aload(self) -> List[Document]:
def aload(self) -> List[Document]: # type: ignore
"""Load text from the urls in web_path async into Documents."""

results = self.scrape_all(self.web_paths)
Expand Down
4 changes: 4 additions & 0 deletions libs/core/langchain_core/document_loaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def load(self) -> List[Document]:
"""Load data into Document objects."""
return list(self.lazy_load())

async def aload(self) -> List[Document]:
"""Load data into Document objects."""
return [document async for document in self.alazy_load()]

def load_and_split(
self, text_splitter: Optional[TextSplitter] = None
) -> List[Document]:
Expand Down
1 change: 1 addition & 0 deletions libs/core/tests/unit_tests/document_loaders/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ def lazy_load(self) -> Iterator[Document]:
docs = loader.load()
assert docs == [Document(page_content="foo"), Document(page_content="bar")]
assert docs == [doc async for doc in loader.alazy_load()]
assert docs == await loader.aload()