From e2d1a032254db0807f0bfe450ad5311566be1acd Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Wed, 10 Jul 2024 12:59:30 -0700 Subject: [PATCH] Properly to_dict --- griptape/common/action.py | 5 +---- tests/unit/common/test_action.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/griptape/common/action.py b/griptape/common/action.py index b819e2ad6..18ca45cfc 100644 --- a/griptape/common/action.py +++ b/griptape/common/action.py @@ -29,14 +29,11 @@ class Action(SerializableMixin): path: Optional[str] = field(default=None, metadata={"serializable": True}) input: dict = field(factory=dict, metadata={"serializable": True}) tool: Optional[BaseTool] = field(default=None) - output: Optional[BaseArtifact] = field(default=None, metadata={"serializable": True}) + output: Optional[BaseArtifact] = field(default=None) def __str__(self) -> str: return json.dumps(self.to_dict()) - def to_dict(self) -> dict: - return {"tag": self.tag, "name": self.name, "path": self.path, "input": self.input} - def to_native_tool_name(self) -> str: parts = [self.name] diff --git a/tests/unit/common/test_action.py b/tests/unit/common/test_action.py index e29d12b7a..9de695d80 100644 --- a/tests/unit/common/test_action.py +++ b/tests/unit/common/test_action.py @@ -10,11 +10,17 @@ def action(self) -> Action: def test__str__(self, action: Action): assert str(action) == json.dumps( - {"tag": "TestTag", "name": "TestName", "path": "TestPath", "input": {"foo": "bar"}} + {"type": "Action", "tag": "TestTag", "name": "TestName", "path": "TestPath", "input": {"foo": "bar"}} ) def test_to_dict(self, action: Action): - assert action.to_dict() == {"tag": "TestTag", "name": "TestName", "path": "TestPath", "input": {"foo": "bar"}} + assert action.to_dict() == { + "tag": "TestTag", + "name": "TestName", + "path": "TestPath", + "input": {"foo": "bar"}, + "type": "Action", + } def test_to_native_tool_name(self, action: Action): assert action.to_native_tool_name() == "TestName_TestPath"