community: Implement lazy_load() for WhatsAppChatLoader (#18677)

Integration test:
`tests/integration_tests/document_loaders/test_whatsapp_chat.py`
This commit is contained in:
Christophe Bornet 2024-03-06 19:03:46 +01:00 committed by GitHub
parent f414f5cdb9
commit ed36f9f604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
import re
from pathlib import Path
from typing import List
from typing import Iterator
from langchain_core.documents import Document
@ -19,8 +19,7 @@ class WhatsAppChatLoader(BaseLoader):
"""Initialize with path."""
self.file_path = path
def load(self) -> List[Document]:
"""Load documents."""
def lazy_load(self) -> Iterator[Document]:
p = Path(self.file_path)
text_content = ""
@ -62,4 +61,4 @@ class WhatsAppChatLoader(BaseLoader):
metadata = {"source": str(p)}
return [Document(page_content=text_content, metadata=metadata)]
yield Document(page_content=text_content, metadata=metadata)