-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
@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}) | ||
|
||
@classmethod | ||
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) | ||
elif value.lower() == "false": | ||
return BooleanArtifact(False) | ||
raise ValueError(f"Cannot convert string literal '{value}' to BooleanArtifact") | ||
|
||
def __add__(self, other: BaseArtifact) -> BooleanArtifact: | ||
raise ValueError("Cannot add BooleanArtifact with other artifacts") | ||