Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let Notion document loader support utf-8 and make it default. #10613

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libs/langchain/langchain/document_loaders/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
class NotionDirectoryLoader(BaseLoader):
"""Load `Notion directory` dump."""

def __init__(self, path: str):
def __init__(self, path: str, *, encoding: str = "utf-8") -> None:
"""Initialize with a file path."""
self.file_path = path
self.encoding = encoding

def load(self) -> List[Document]:
"""Load documents."""
ps = list(Path(self.file_path).glob("**/*.md"))
paths = list(Path(self.file_path).glob("**/*.md"))
docs = []
for p in ps:
with open(p) as f:
for p in paths:
with open(p, encoding=self.encoding) as f:
text = f.read()
metadata = {"source": str(p)}
docs.append(Document(page_content=text, metadata=metadata))
Expand Down
Loading