base_artifact

Bases: SerializableMixin , ABC

Attributes

NameTypeDescription
idstrThe unique identifier of the Artifact. Defaults to a random UUID.
referenceOptional[Reference]The optional Reference to the Artifact.
metadict[str, Any]The metadata associated with the Artifact. Defaults to an empty dictionary.
namestrThe name of the Artifact. Defaults to the id.
valueAnyThe value of the Artifact.
encodingstrThe encoding to use when encoding/decoding the value.
encoding_error_handlerstrThe error on_event to use when encoding/decoding the value.
Source Code in griptape/artifacts/base_artifact.py
@define
class BaseArtifact(SerializableMixin, ABC):
    """Serves as the base class for all Artifacts.

    Artifacts are used to encapsulate data and enhance it with metadata.

    Attributes:
        id: The unique identifier of the Artifact. Defaults to a random UUID.
        reference: The optional Reference to the Artifact.
        meta: The metadata associated with the Artifact. Defaults to an empty dictionary.
        name: The name of the Artifact. Defaults to the id.
        value: The value of the Artifact.
        encoding: The encoding to use when encoding/decoding the value.
        encoding_error_handler: The error on_event to use when encoding/decoding the value.
    """

    id: str = field(default=Factory(lambda: uuid.uuid4().hex), kw_only=True, metadata={"serializable": True})
    reference: Optional[Reference] = field(default=None, kw_only=True, metadata={"serializable": True})
    meta: dict[str, Any] = field(factory=dict, kw_only=True, metadata={"serializable": True})
    name: str = field(
        default=Factory(lambda self: self.id, takes_self=True),
        kw_only=True,
        metadata={"serializable": True},
    )
    value: Any = field()
    encoding_error_handler: str = field(default="strict", kw_only=True)
    encoding: str = field(default="utf-8", kw_only=True)

    def __str__(self) -> str:
        return self.to_text()

    def __bool__(self) -> bool:
        return bool(self.value)

    def __len__(self) -> int:
        return len(self.value)

    def to_bytes(self, **kwargs) -> bytes:
        return self.to_text().encode(encoding=self.encoding, errors=self.encoding_error_handler)

    @abstractmethod
    def to_text(self) -> str: ...
  • encoding = field(default='utf-8', kw_only=True) class-attribute instance-attribute

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

  • id = field(default=Factory(lambda: uuid.uuid4().hex), kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • meta = field(factory=dict, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • name = field(default=Factory(lambda self: self.id, takes_self=True), kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • reference = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

  • value = field() class-attribute instance-attribute

bool()

Source Code in griptape/artifacts/base_artifact.py
def __bool__(self) -> bool:
    return bool(self.value)

len()

Source Code in griptape/artifacts/base_artifact.py
def __len__(self) -> int:
    return len(self.value)

str()

Source Code in griptape/artifacts/base_artifact.py
def __str__(self) -> str:
    return self.to_text()

to_bytes(**kwargs)

Source Code in griptape/artifacts/base_artifact.py
def to_bytes(self, **kwargs) -> bytes:
    return self.to_text().encode(encoding=self.encoding, errors=self.encoding_error_handler)

to_text()abstractmethod

Source Code in griptape/artifacts/base_artifact.py
@abstractmethod
def to_text(self) -> str: ...

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