Skip to content

Commit

Permalink
community[minor]: Implement lazy_load() for OutlookMessageLoader (lan…
Browse files Browse the repository at this point in the history
…gchain-ai#18668)

Integration test:
`tests/integration_tests/document_loaders/test_email.py`
  • Loading branch information
cbornet authored and gkorland committed Mar 30, 2024
1 parent a0b3296 commit 9eed766
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions libs/community/langchain_community/document_loaders/email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Any, List
from typing import Any, Iterator, List

from langchain_core.documents import Document

Expand Down Expand Up @@ -99,19 +99,16 @@ def __init__(self, file_path: str):
"`pip install extract_msg`"
)

def load(self) -> List[Document]:
"""Load data into document objects."""
def lazy_load(self) -> Iterator[Document]:
import extract_msg

msg = extract_msg.Message(self.file_path)
return [
Document(
page_content=msg.body,
metadata={
"source": self.file_path,
"subject": msg.subject,
"sender": msg.sender,
"date": msg.date,
},
)
]
yield Document(
page_content=msg.body,
metadata={
"source": self.file_path,
"subject": msg.subject,
"sender": msg.sender,
"date": msg.date,
},
)

0 comments on commit 9eed766

Please sign in to comment.