File reader
FileReader
¶
Bases: Reader
The agentUniverse(aU) file reader class.
FileReader is used to load data from files based on the provided file paths.
Attributes:
| Name | Type | Description |
|---|---|---|
file_readers |
Dict[str, Type[Reader]]
|
The file reader dictionary, |
Source code in agentuniverse/agent/action/knowledge/reader/file/file_reader.py
Python
class FileReader(Reader):
"""The agentUniverse(aU) file reader class.
FileReader is used to load data from files based on the provided file paths.
Attributes:
file_readers (Dict[str, Type[Reader]], optional): The file reader dictionary,
the key is the suffix of the file, and the value is the specific file reader class.
"""
file_readers: Dict[str, Type[Reader]] = DEFAULT_FILE_READERS
def load_data(self, file_paths: List[Path], ext_info: Optional[Dict] = None) -> List[Document]:
document_list = []
for file_path in file_paths:
file_suffix = file_path.suffix.lower()
if file_suffix in self.file_readers.keys():
file_reader = self.file_readers[file_suffix]()
document_list.extend(file_reader.load_data(file=file_path, ext_info=ext_info))
return document_list