Skip to content

boolean_artifact

BooleanArtifact

Bases: BaseArtifact

Stores a boolean value.

Attributes:

Name Type Description
value bool

The boolean value.

Source code in griptape/artifacts/boolean_artifact.py
@define
class BooleanArtifact(BaseArtifact):
    """Stores a boolean value.

    Attributes:
        value: The boolean value.
    """

    value: bool = field(converter=bool, metadata={"serializable": True})

    @classmethod
    def parse_bool(cls, value: Union[str, bool]) -> BooleanArtifact:
        """Convert a string literal or bool to a BooleanArtifact. The string must be either "true" or "false"."""
        if value is not None:
            if isinstance(value, str):
                if value.lower() == "true":
                    return BooleanArtifact(value=True)
                elif value.lower() == "false":
                    return BooleanArtifact(value=False)
            elif isinstance(value, bool):
                return BooleanArtifact(value)
        raise ValueError(f"Cannot convert '{value}' to BooleanArtifact")

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

    def __eq__(self, value: object) -> bool:
        return self.value == value

    def to_text(self) -> str:
        return str(self.value).lower()

value: bool = field(converter=bool, metadata={'serializable': True}) class-attribute instance-attribute

__add__(other)

Source code in griptape/artifacts/boolean_artifact.py
def __add__(self, other: BaseArtifact) -> BooleanArtifact:
    raise ValueError("Cannot add BooleanArtifact with other artifacts")

__eq__(value)

Source code in griptape/artifacts/boolean_artifact.py
def __eq__(self, value: object) -> bool:
    return self.value == value

parse_bool(value) classmethod

Convert a string literal or bool to a BooleanArtifact. The string must be either "true" or "false".

Source code in griptape/artifacts/boolean_artifact.py
@classmethod
def parse_bool(cls, value: Union[str, bool]) -> BooleanArtifact:
    """Convert a string literal or bool to a BooleanArtifact. The string must be either "true" or "false"."""
    if value is not None:
        if isinstance(value, str):
            if value.lower() == "true":
                return BooleanArtifact(value=True)
            elif value.lower() == "false":
                return BooleanArtifact(value=False)
        elif isinstance(value, bool):
            return BooleanArtifact(value)
    raise ValueError(f"Cannot convert '{value}' to BooleanArtifact")

to_text()

Source code in griptape/artifacts/boolean_artifact.py
def to_text(self) -> str:
    return str(self.value).lower()