Skip to content

Commit

Permalink
community[minor]: Implement lazy_load() for FacebookChatLoader (langc…
Browse files Browse the repository at this point in the history
…hain-ai#18669)

Integration test:
`tests/integration_tests/document_loaders/test_facebook_chat.py`
  • Loading branch information
cbornet authored and gkorland committed Mar 30, 2024
1 parent 0aaddf2 commit 81a0187
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -29,8 +29,7 @@ def __init__(self, path: str):
"""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:
Expand All @@ -43,4 +42,4 @@ def load(self) -> List[Document]:
)
metadata = {"source": str(p)}

return [Document(page_content=text, metadata=metadata)]
yield Document(page_content=text, metadata=metadata)

0 comments on commit 81a0187

Please sign in to comment.