Skip to content

Commit

Permalink
Properly to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Jul 10, 2024
1 parent d55ce6e commit e2d1a03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions griptape/common/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
10 changes: 8 additions & 2 deletions tests/unit/common/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e2d1a03

Please sign in to comment.