base_artifact#

Bases: SerializableMixin “) , ABC

Attributes#

Name

Type

Description

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.id" title="id = field(default=Factory(lambda: uuid.uuid4().hex), kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.id)"><code class="language-python">id</code></a>

str

The unique identifier of the Artifact. Defaults to a random UUID.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.reference" title="reference = field(default=None, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.reference)"><code class="language-python">reference</code></a>

<a href="../common#griptape.common.Reference" title="Reference (griptape.common.Reference)"><code class="language-python">Optional[Reference]</code></a>

The optional Reference to the Artifact.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.meta" title="meta = field(factory=dict, kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.meta)"><code class="language-python">meta</code></a>

dict[str, Any]

The metadata associated with the Artifact. Defaults to an empty dictionary.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.name" title="name = field(default=Factory(lambda self: self.id, takes_self=True), kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.name)"><code class="language-python">name</code></a>

str

The name of the Artifact. Defaults to the id.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.value" title="value = field() class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.value)"><code class="language-python">value</code></a>

Any

The value of the Artifact.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.encoding" title="encoding = field(default='utf-8', kw_only=True) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.encoding)"><code class="language-python">encoding</code></a>

str

The encoding to use when encoding/decoding the value.<br/>

<a href="base_artifact.mdx#griptape.artifacts.base_artifact.BaseArtifact.encoding_error_handler" title="encoding_error_handler = field(default='strict', kw_only=True) class-attribute instance-attribute (griptape.artifacts.base_artifact.BaseArtifact.encoding_error_handler)"><code class="language-python">encoding_error_handler</code></a>

str

The error on_event to use when encoding/decoding the value.<br/>

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: ...