model_artifact

model_artifact#

Bases: GenericArtifact[BaseModel “)

Attributes#

Name

Type

Description

<a href="model_artifact.mdx#griptape.artifacts.model_artifact.ModelArtifact.value" title="value = field(metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.model_artifact.ModelArtifact.value)"><code class="language-python">value</code></a>

BaseModel

The pydantic model to store.<br/>

Source Code in griptape/artifacts/model_artifact.py

@define
class ModelArtifact(GenericArtifact[BaseModel]):
    """Stores Pydantic models as Artifacts.

    Required since Pydantic models require a custom serialization method.

    Attributes:
        value: The pydantic model to store.
    """

    # We must explicitly define the type rather than rely on the parent T since
    # generic type information is lost at runtime.
    value: BaseModel = field(metadata={"serializable": True})

    def to_text(self) -> str:
        return self.value.model_dump_json()
  • value = field(metadata={'serializable': True}) class-attribute instance-attribute

to_text()#

Source Code in griptape/artifacts/model_artifact.py

def to_text(self) -> str:
    return self.value.model_dump_json()