Update text.py (#2195)

Add encoding parameter when open txt file to support unicode files.
This commit is contained in:
Jeru2023 2023-03-30 22:52:17 +08:00 committed by GitHub
parent 5d86a6acf1
commit 64b9843b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ class TextLoader(BaseLoader):
def load(self) -> List[Document]: def load(self) -> List[Document]:
"""Load from file path.""" """Load from file path."""
with open(self.file_path) as f: with open(self.file_path, encoding="utf-8") as f:
text = f.read() text = f.read()
metadata = {"source": self.file_path} metadata = {"source": self.file_path}
return [Document(page_content=text, metadata=metadata)] return [Document(page_content=text, metadata=metadata)]