Skip to content

Commit

Permalink
Add BooleanArtifact
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo committed Jun 26, 2024
1 parent 2a347f3 commit 75e1fd9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions griptape/artifacts/boolean_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations
from typing import Any
from attrs import define, field
from griptape.artifacts import BaseArtifact

Check warning on line 4 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L1-L4

Added lines #L1 - L4 were not covered by tests


@define
class BooleanArtifact(BaseArtifact):
value: bool = field(converter=bool, metadata={"serializable": True})
meta: dict[str, Any] = field(factory=dict, kw_only=True, metadata={"serializable": True})

Check warning on line 10 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L8-L10

Added lines #L8 - L10 were not covered by tests

@classmethod

Check warning on line 12 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L12

Added line #L12 was not covered by tests
def parse_bool(cls, value: str) -> BooleanArtifact:
"""
Convert a string literal to a BooleanArtifact. The string must be either "true" or "false" with any casing.
"""
if value is not None:
if value.lower() == "true":
return BooleanArtifact(True)

Check warning on line 19 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L19

Added line #L19 was not covered by tests
elif value.lower() == "false":
return BooleanArtifact(False)
raise ValueError(f"Cannot convert string literal '{value}' to BooleanArtifact")

Check warning on line 22 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L21-L22

Added lines #L21 - L22 were not covered by tests

def __add__(self, other: BaseArtifact) -> BooleanArtifact:
raise ValueError("Cannot add BooleanArtifact with other artifacts")

Check warning on line 25 in griptape/artifacts/boolean_artifact.py

View check run for this annotation

Codecov / codecov/patch

griptape/artifacts/boolean_artifact.py#L24-L25

Added lines #L24 - L25 were not covered by tests

0 comments on commit 75e1fd9

Please sign in to comment.