mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 22:28:03 +00:00
add encoding parameter to ObsidianLoader (#1752)
This commit is contained in:
parent
3cf493b089
commit
08f23c95d9
@ -9,16 +9,17 @@ from langchain.document_loaders.base import BaseLoader
|
|||||||
class ObsidianLoader(BaseLoader):
|
class ObsidianLoader(BaseLoader):
|
||||||
"""Loader that loads Obsidian files from disk."""
|
"""Loader that loads Obsidian files from disk."""
|
||||||
|
|
||||||
def __init__(self, path: str):
|
def __init__(self, path: str, encoding: str = "UTF-8"):
|
||||||
"""Initialize with path."""
|
"""Initialize with 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"))
|
ps = list(Path(self.file_path).glob("**/*.md"))
|
||||||
docs = []
|
docs = []
|
||||||
for p in ps:
|
for p in ps:
|
||||||
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user