Skip to content

Commit d293431

Browse files
authored
core[minor]: Add aload to document loader (langchain-ai#19936)
Add aload to document loader
1 parent 31a641a commit d293431

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

libs/community/langchain_community/document_loaders/web_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def lazy_load(self) -> Iterator[Document]:
251251
metadata = _build_metadata(soup, path)
252252
yield Document(page_content=text, metadata=metadata)
253253

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

257257
results = self.scrape_all(self.web_paths)

libs/core/langchain_core/document_loaders/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def load(self) -> List[Document]:
2828
"""Load data into Document objects."""
2929
return list(self.lazy_load())
3030

31+
async def aload(self) -> List[Document]:
32+
"""Load data into Document objects."""
33+
return [document async for document in self.alazy_load()]
34+
3135
def load_and_split(
3236
self, text_splitter: Optional[TextSplitter] = None
3337
) -> List[Document]:

libs/core/tests/unit_tests/document_loaders/test_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ def lazy_load(self) -> Iterator[Document]:
6464
docs = loader.load()
6565
assert docs == [Document(page_content="foo"), Document(page_content="bar")]
6666
assert docs == [doc async for doc in loader.alazy_load()]
67+
assert docs == await loader.aload()

0 commit comments

Comments
 (0)