community[minor]: Implement lazy_load() for FacebookChatLoader (#18669)

Integration test:
`tests/integration_tests/document_loaders/test_facebook_chat.py`
This commit is contained in:
Christophe Bornet 2024-03-06 15:15:00 +01:00 committed by GitHub
parent 20794bb889
commit 623dfcc55c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import datetime
import json
from pathlib import Path
from typing import List
from typing import Iterator
from langchain_core.documents import Document
@ -29,8 +29,7 @@ class FacebookChatLoader(BaseLoader):
"""Initialize with a path."""
self.file_path = path
def load(self) -> List[Document]:
"""Load documents."""
def lazy_load(self) -> Iterator[Document]:
p = Path(self.file_path)
with open(p, encoding="utf8") as f:
@ -43,4 +42,4 @@ class FacebookChatLoader(BaseLoader):
)
metadata = {"source": str(p)}
return [Document(page_content=text, metadata=metadata)]
yield Document(page_content=text, metadata=metadata)