base_file_loader
Adapted from the Griptape AI Framework documentation.
A = TypeVar('A', bound=BaseArtifact)
module-attribute
Bases:
BaseLoader[Union[str, PathLike], bytes, A]
, ABC
Source Code in griptape/loaders/base_file_loader.py
@define class BaseFileLoader(BaseLoader[Union[str, PathLike], bytes, A], ABC): file_manager_driver: BaseFileManagerDriver = field( default=Factory(lambda: LocalFileManagerDriver()), kw_only=True, ) encoding: str = field(default="utf-8", kw_only=True) def fetch(self, source: str | PathLike) -> bytes: # TODO: This is silly. `load_file` decodes the bytes and then we immediately re-encode them. data = self.file_manager_driver.load_file(str(source)).value if isinstance(data, str): return data.encode(self.encoding) return data def save(self, destination: str | PathLike, artifact: A) -> None: """Saves the Artifact to a destination.""" artifact.encoding = self.encoding self.file_manager_driver.save_file(str(destination), artifact.to_bytes())
encoding = field(default='utf-8', kw_only=True)
class-attribute instance-attributefile_manager_driver = field(default=Factory(lambda: LocalFileManagerDriver()), kw_only=True)
class-attribute instance-attribute
fetch(source)
Source Code in griptape/loaders/base_file_loader.py
def fetch(self, source: str | PathLike) -> bytes: # TODO: This is silly. `load_file` decodes the bytes and then we immediately re-encode them. data = self.file_manager_driver.load_file(str(source)).value if isinstance(data, str): return data.encode(self.encoding) return data
save(destination, artifact)
Source Code in griptape/loaders/base_file_loader.py
def save(self, destination: str | PathLike, artifact: A) -> None: """Saves the Artifact to a destination.""" artifact.encoding = self.encoding self.file_manager_driver.save_file(str(destination), artifact.to_bytes())
- On this page
- fetch(source)
- save(destination, artifact)
Could this page be better? Report a problem or suggest an addition!