Skip to content

refactor: let Artifact validator handle base64 decoding across all providers #138

Description

@Kamilbenkirane

Summary

Multiple provider clients manually call base64.b64decode() before passing data to ImageArtifact(data=...) or VideoArtifact(data=...). The Artifact base class already has a @field_validator("data", mode="before") that automatically decodes base64 strings to bytes. We should pass the base64 string directly and let the validator handle it.

Already fixed in #135 (Vertex PR) for Google providers:

  • modalities/images/providers/google/gemini.py
  • modalities/images/providers/google/imagen.py
  • modalities/videos/providers/google/client.py

Remaining instances

  • modalities/images/providers/openai/client.py (lines 64, 146)
  • modalities/images/providers/xai/client.py (line 87)
  • modalities/images/providers/ollama/client.py (lines 56, 118)
  • modalities/images/providers/byteplus/client.py (lines 83, 165)
  • modalities/videos/providers/openai/client.py (line 58)
  • modalities/audio/providers/google/client.py (line 65)

Pattern

Replace:

image_bytes = base64.b64decode(base64_data)
artifacts.append(ImageArtifact(data=image_bytes, ...))

With:

artifacts.append(ImageArtifact(data=base64_data, ...))

Remove unused import base64 where applicable.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions