boolean_artifact#
Bases: BaseArtifact “)
Attributes#
Name |
Type |
Description |
|---|---|---|
<a href="boolean_artifact.mdx#griptape.artifacts.boolean_artifact.BooleanArtifact.value" title="value = field(converter=bool, metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.boolean_artifact.BooleanArtifact.value)"><code class="language-python">value</code></a> |
bool |
The boolean value.<br/> |
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)
if 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 = 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#
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)
if 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()