Bases: BaseComponent
Base wrapper around llama-index reader
To use the LIBaseReader, you need to implement the _get_wrapped_class method to
return the relevant llama-index reader class that you want to wrap.
Example:
| ```python
class DirectoryReader(LIBaseReader):
def _get_wrapped_class(self) -> Type["BaseReader"]:
from llama_index import SimpleDirectoryReader
return SimpleDirectoryReader
```
|
Source code in libs/kotaemon/kotaemon/loaders/base.py
| class LIReaderMixin(BaseComponent):
"""Base wrapper around llama-index reader
To use the LIBaseReader, you need to implement the _get_wrapped_class method to
return the relevant llama-index reader class that you want to wrap.
Example:
```python
class DirectoryReader(LIBaseReader):
def _get_wrapped_class(self) -> Type["BaseReader"]:
from llama_index import SimpleDirectoryReader
return SimpleDirectoryReader
```
"""
def _get_wrapped_class(self) -> Type["LIBaseReader"]:
raise NotImplementedError(
"Please return the relevant llama-index class in in _get_wrapped_class"
)
def __init__(self, *args, **kwargs):
self._reader_class = self._get_wrapped_class()
self._reader = self._reader_class(*args, **kwargs)
super().__init__()
def __setattr__(self, name: str, value: Any) -> None:
if name.startswith("_"):
return super().__setattr__(name, value)
return setattr(self._reader, name, value)
def __getattr__(self, name: str) -> Any:
return getattr(self._reader, name)
def load_data(self, *args, **kwargs: Any) -> List[Document]:
documents = self._reader.load_data(*args, **kwargs)
# convert Document to new base class from kotaemon
converted_documents = [Document.from_dict(doc.to_dict()) for doc in documents]
return converted_documents
def run(self, *args, **kwargs: Any) -> List[Document]:
return self.load_data(*args, **kwargs)
|