mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-04 02:33:05 +00:00
community: Implement lazy_load() for WhatsAppChatLoader (#18677)
Integration test: `tests/integration_tests/document_loaders/test_whatsapp_chat.py`
This commit is contained in:
parent
f414f5cdb9
commit
ed36f9f604
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import Iterator
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
@ -19,8 +19,7 @@ class WhatsAppChatLoader(BaseLoader):
|
|||||||
"""Initialize with path."""
|
"""Initialize with path."""
|
||||||
self.file_path = path
|
self.file_path = path
|
||||||
|
|
||||||
def load(self) -> List[Document]:
|
def lazy_load(self) -> Iterator[Document]:
|
||||||
"""Load documents."""
|
|
||||||
p = Path(self.file_path)
|
p = Path(self.file_path)
|
||||||
text_content = ""
|
text_content = ""
|
||||||
|
|
||||||
@ -62,4 +61,4 @@ class WhatsAppChatLoader(BaseLoader):
|
|||||||
|
|
||||||
metadata = {"source": str(p)}
|
metadata = {"source": str(p)}
|
||||||
|
|
||||||
return [Document(page_content=text_content, metadata=metadata)]
|
yield Document(page_content=text_content, metadata=metadata)
|
||||||
|
Loading…
Reference in New Issue
Block a user