|
|
@ -8,16 +8,17 @@ from langchain.document_loaders.base import BaseLoader
|
|
|
|
class NotionDirectoryLoader(BaseLoader):
|
|
|
|
class NotionDirectoryLoader(BaseLoader):
|
|
|
|
"""Load `Notion directory` dump."""
|
|
|
|
"""Load `Notion directory` dump."""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, path: str):
|
|
|
|
def __init__(self, path: str, *, encoding: str = "utf-8") -> None:
|
|
|
|
"""Initialize with a file path."""
|
|
|
|
"""Initialize with a file path."""
|
|
|
|
self.file_path = path
|
|
|
|
self.file_path = path
|
|
|
|
|
|
|
|
self.encoding = encoding
|
|
|
|
|
|
|
|
|
|
|
|
def load(self) -> List[Document]:
|
|
|
|
def load(self) -> List[Document]:
|
|
|
|
"""Load documents."""
|
|
|
|
"""Load documents."""
|
|
|
|
ps = list(Path(self.file_path).glob("**/*.md"))
|
|
|
|
paths = list(Path(self.file_path).glob("**/*.md"))
|
|
|
|
docs = []
|
|
|
|
docs = []
|
|
|
|
for p in ps:
|
|
|
|
for p in paths:
|
|
|
|
with open(p) as f:
|
|
|
|
with open(p, encoding=self.encoding) as f:
|
|
|
|
text = f.read()
|
|
|
|
text = f.read()
|
|
|
|
metadata = {"source": str(p)}
|
|
|
|
metadata = {"source": str(p)}
|
|
|
|
docs.append(Document(page_content=text, metadata=metadata))
|
|
|
|
docs.append(Document(page_content=text, metadata=metadata))
|
|
|
|