blob_artifact

Bases: BaseArtifact

Attributes

NameTypeDescription
valuebytesThe binary data.
Source Code in griptape/artifacts/blob_artifact.py
@define
class BlobArtifact(BaseArtifact):
    """Stores arbitrary binary data.

    Attributes:
        value: The binary data.
    """

    value: bytes = field(
        converter=lambda value: value if isinstance(value, bytes) else str(value).encode(),
        metadata={"serializable": True},
    )

    @property
    def base64(self) -> str:
        return base64.b64encode(self.value).decode(self.encoding)

    @property
    def mime_type(self) -> str:
        return "application/octet-stream"

    def to_bytes(self, **kwargs) -> bytes:
        return self.value

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

  • mime_type property

  • value = field(converter=lambda value: value if isinstance(value, bytes) else str(value).encode(), metadata={'serializable': True}) class-attribute instance-attribute

to_bytes(**kwargs)

Source Code in griptape/artifacts/blob_artifact.py
def to_bytes(self, **kwargs) -> bytes:
    return self.value

to_text()

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

Could this page be better? Report a problem or suggest an addition!