mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-08-26 16:55:38 -04:00
e51fad1488
Co-authored-by: Harrison Chase <harrisonchase@Harrisons-MBP.attlocal.net>
21 lines
580 B
Python
21 lines
580 B
Python
"""Load text files."""
|
|
from typing import List
|
|
|
|
from langchain.docstore.document import Document
|
|
from langchain.document_loaders.base import BaseLoader
|
|
|
|
|
|
class TextLoader(BaseLoader):
|
|
"""Load text files."""
|
|
|
|
def __init__(self, file_path: str):
|
|
"""Initialize with file path."""
|
|
self.file_path = file_path
|
|
|
|
def load(self) -> List[Document]:
|
|
"""Load from file path."""
|
|
with open(self.file_path) as f:
|
|
text = f.read()
|
|
metadata = {"source": self.file_path}
|
|
return [Document(page_content=text, metadata=metadata)]
|