Skip to content

Blob artifact

BlobArtifact

Bases: BaseArtifact

Source code in griptape/griptape/artifacts/blob_artifact.py
@define(frozen=True)
class BlobArtifact(BaseArtifact):
    value: bytes = field(converter=BaseArtifact.value_to_bytes)
    dir_name: str | None = field(default=None, kw_only=True)
    encoding: str = field(default="utf-8", kw_only=True)
    encoding_error_handler: str = field(default="strict", kw_only=True)

    def __add__(self, other: BlobArtifact) -> BlobArtifact:
        return BlobArtifact(self.value + other.value, name=self.name)

    @property
    def full_path(self) -> str:
        return os.path.join(self.dir_name, self.name) if self.dir_name else self.name

    def to_text(self) -> str:
        return self.value.decode(encoding=self.encoding, errors=self.encoding_error_handler)

    def to_dict(self) -> dict:
        from griptape.schemas import BlobArtifactSchema

        return dict(BlobArtifactSchema().dump(self))

dir_name: str | None = field(default=None, kw_only=True) class-attribute instance-attribute

encoding: str = field(default='utf-8', kw_only=True) class-attribute instance-attribute

encoding_error_handler: str = field(default='strict', kw_only=True) class-attribute instance-attribute

full_path: str property

value: bytes = field(converter=BaseArtifact.value_to_bytes) class-attribute instance-attribute

__add__(other)

Source code in griptape/griptape/artifacts/blob_artifact.py
def __add__(self, other: BlobArtifact) -> BlobArtifact:
    return BlobArtifact(self.value + other.value, name=self.name)

to_dict()

Source code in griptape/griptape/artifacts/blob_artifact.py
def to_dict(self) -> dict:
    from griptape.schemas import BlobArtifactSchema

    return dict(BlobArtifactSchema().dump(self))

to_text()

Source code in griptape/griptape/artifacts/blob_artifact.py
def to_text(self) -> str:
    return self.value.decode(encoding=self.encoding, errors=self.encoding_error_handler)