mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
community[minor]: Implement lazy_load() for FacebookChatLoader (#18669)
Integration test: `tests/integration_tests/document_loaders/test_facebook_chat.py`
This commit is contained in:
parent
20794bb889
commit
623dfcc55c
@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
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
|
||||||
|
|
||||||
@ -29,8 +29,7 @@ class FacebookChatLoader(BaseLoader):
|
|||||||
"""Initialize with a path."""
|
"""Initialize with a 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)
|
||||||
|
|
||||||
with open(p, encoding="utf8") as f:
|
with open(p, encoding="utf8") as f:
|
||||||
@ -43,4 +42,4 @@ class FacebookChatLoader(BaseLoader):
|
|||||||
)
|
)
|
||||||
metadata = {"source": str(p)}
|
metadata = {"source": str(p)}
|
||||||
|
|
||||||
return [Document(page_content=text, metadata=metadata)]
|
yield Document(page_content=text, metadata=metadata)
|
||||||
|
Loading…
Reference in New Issue
Block a user