Skip to content

Image artifact schema

ImageArtifactSchema

Bases: BaseArtifactSchema

Source code in griptape/griptape/schemas/artifacts/image_artifact_schema.py
class ImageArtifactSchema(BaseArtifactSchema):
    base64 = fields.Str()
    mime_type = fields.Str()
    width = fields.Int()
    height = fields.Int()
    model = fields.Str()
    prompt = fields.Str()

    @post_load
    def make_obj(self, data, **kwargs):
        from griptape.artifacts import ImageArtifact

        if "base64" in data:
            import base64

            image_bytes = base64.b64decode(data["base64"])
            data["value"] = image_bytes
            del data["base64"]

        return ImageArtifact(**data)

base64 = fields.Str() class-attribute instance-attribute

height = fields.Int() class-attribute instance-attribute

mime_type = fields.Str() class-attribute instance-attribute

model = fields.Str() class-attribute instance-attribute

prompt = fields.Str() class-attribute instance-attribute

width = fields.Int() class-attribute instance-attribute

make_obj(data, **kwargs)

Source code in griptape/griptape/schemas/artifacts/image_artifact_schema.py
@post_load
def make_obj(self, data, **kwargs):
    from griptape.artifacts import ImageArtifact

    if "base64" in data:
        import base64

        image_bytes = base64.b64decode(data["base64"])
        data["value"] = image_bytes
        del data["base64"]

    return ImageArtifact(**data)