-
Notifications
You must be signed in to change notification settings - Fork 175
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
1 parent
58a5a63
commit c2d4e36
Showing
11 changed files
with
73 additions
and
45 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
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
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
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,22 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from attrs import define, field | ||
|
||
from griptape.artifacts import BaseArtifact, TextArtifact | ||
|
||
|
||
def value_to_str(value: Any) -> str: | ||
if isinstance(value, dict): | ||
return "\n".join(f"{key}: {val}" for key, val in value.items()) | ||
else: | ||
return str(value) | ||
|
||
|
||
@define | ||
class CsvRowArtifact(TextArtifact): | ||
value: str = field(converter=value_to_str, metadata={"serializable": True}) | ||
|
||
def __add__(self, other: BaseArtifact) -> TextArtifact: | ||
return TextArtifact(self.value + "\n" + other.value) |
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
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
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
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
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
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,27 @@ | ||
from griptape.artifacts import CsvRowArtifact | ||
|
||
|
||
class TestCsvRowArtifact: | ||
def test_value_type_conversion(self): | ||
assert CsvRowArtifact({"foo": "bar"}).value == "foo: bar" | ||
assert CsvRowArtifact({"foo": {"bar": "baz"}}).value == "foo: {'bar': 'baz'}" | ||
assert CsvRowArtifact('{"foo": "bar"}').value == '{"foo": "bar"}' | ||
|
||
def test___add__(self): | ||
assert (CsvRowArtifact({"test1": "foo"}) + CsvRowArtifact({"test2": "bar"})).value == "test1: foo\ntest2: bar" | ||
|
||
def test_to_text(self): | ||
assert CsvRowArtifact({"test1": "foo|bar", "test2": 1}).to_text() == "test1: foo|bar\ntest2: 1" | ||
|
||
def test_to_dict(self): | ||
assert CsvRowArtifact({"test1": "foo"}).to_dict()["value"] == "test1: foo" | ||
|
||
def test_name(self): | ||
artifact = CsvRowArtifact({}) | ||
|
||
assert artifact.name == artifact.id | ||
assert CsvRowArtifact({}, name="bar").name == "bar" | ||
|
||
def test___bool__(self): | ||
assert not bool(CsvRowArtifact({})) | ||
assert bool(CsvRowArtifact({"foo": "bar"})) |
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