mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +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):
|
||||
"""Loader that loads Obsidian files from disk."""
|
||||
|
||||
def __init__(self, path: str):
|
||||
def __init__(self, path: str, encoding: str = "UTF-8"):
|
||||
"""Initialize with path."""
|
||||
self.file_path = path
|
||||
self.encoding = encoding
|
||||
|
||||
def load(self) -> List[Document]:
|
||||
"""Load documents."""
|
||||
ps = list(Path(self.file_path).glob("**/*.md"))
|
||||
docs = []
|
||||
for p in ps:
|
||||
with open(p) as f:
|
||||
with open(p, encoding=self.encoding) as f:
|
||||
text = f.read()
|
||||
metadata = {"source": str(p)}
|
||||
docs.append(Document(page_content=text, metadata=metadata))
|
||||
|
Loading…
Reference in New Issue
Block a user