Skip to content

Commit

Permalink
Make image format required
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Sep 9, 2024
1 parent c324487 commit d95e116
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Removed `BlobArtifact.dir_name`.
- **BREAKING**: Moved `ImageArtifact.prompt` and `ImageArtifact.model` into `ImageArtifact.meta`.
- **BREAKING**: `ImageArtifact.to_text()` now returns the base64 encoded image.
- **BREAKING**: `ImageArtifact.format` is now required.
- Updated `JsonArtifact` value converter to properly handle more types.
- `AudioArtifact` now subclasses `BlobArtifact` instead of `MediaArtifact`.
- `ImageArtifact` now subclasses `BlobArtifact` instead of `MediaArtifact`.
Expand Down
20 changes: 20 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ audio_artifact = AudioArtifact(
)
```

### `ImageArtifact.format` is now required

`ImageArtifact.format` is now a required parameter. Update any code that does not provide a `format` parameter.

#### Before

```python
image_artifact = ImageArtifact(
b"image_data"
)
```

#### After
```python
image_artifact = ImageArtifact(
b"image_data",
format="jpeg"
)
```

### Changed `CsvRowArtifact.value` from `dict` to `str`.

`CsvRowArtifact`'s `value` is now a `str` instead of a `dict`. Update any logic that expects `dict` to handle `str` instead.
Expand Down
4 changes: 2 additions & 2 deletions griptape/artifacts/image_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class ImageArtifact(BlobArtifact):
Attributes:
value: The image data.
format: The format of the image data. Defaults to "png".
format: The format of the image data.
width: The width of the image.
height: The height of the image
"""

value: bytes = field(metadata={"serializable": True})
format: str = field(default="png", kw_only=True, metadata={"serializable": True})
format: str = field(kw_only=True, metadata={"serializable": True})
width: int = field(kw_only=True, metadata={"serializable": True})
height: int = field(kw_only=True, metadata={"serializable": True})

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/artifacts/test_list_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_child_type(self):

def test_is_type(self):
assert ListArtifact([TextArtifact("foo")]).is_type(TextArtifact)
assert ListArtifact([ImageArtifact(b"", width=1234, height=1234)]).is_type(ImageArtifact)
assert ListArtifact([ImageArtifact(b"", width=1234, height=1234, format="png")]).is_type(ImageArtifact)

def test_has_items(self):
assert not ListArtifact().has_items()
Expand Down

0 comments on commit d95e116

Please sign in to comment.