Skip to content

Commit

Permalink
remove str
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo committed Oct 18, 2024
1 parent 78077b6 commit c9d8b3a
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 27 deletions.
18 changes: 0 additions & 18 deletions griptape/events/action_chunk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,3 @@ class ActionChunkEvent(BaseChunkEvent):
tag: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True})
name: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True})
path: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True})

def __str__(self) -> str:
parts = []

if self.name:
parts.append(self.name)
if self.path:
parts.append(f".{self.path}")
if self.tag:
parts.append(f" ({self.tag})")

if self.partial_input:
if parts:
parts.append(f" {self.partial_input}")
else:
parts.append(self.partial_input)

return "".join(parts)
2 changes: 0 additions & 2 deletions griptape/events/base_chunk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@
@define
class BaseChunkEvent(BaseEvent):
index: int = field(default=0, metadata={"serializable": True})

def __str__(self) -> str: ...
3 changes: 0 additions & 3 deletions griptape/events/text_chunk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
@define
class TextChunkEvent(BaseChunkEvent):
token: str = field(kw_only=True, metadata={"serializable": True})

def __str__(self) -> str:
return self.token
4 changes: 2 additions & 2 deletions griptape/utils/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@define
class Stream:
"""A wrapper for Structures that converts `CompletionChunkEvent`s into an iterator of TextArtifacts.
"""A wrapper for Structures that converts `BaseChunkEvent`s into an iterator of TextArtifacts.
It achieves this by running the Structure in a separate thread, listening for events from the Structure,
and yielding those events.
Expand Down Expand Up @@ -68,7 +68,7 @@ def run(self, *args) -> Iterator[TextArtifact]:
elif isinstance(event, FinishPromptEvent):
yield TextArtifact(value="\n")
elif isinstance(event, TextChunkEvent):
yield TextArtifact(value=str(event))
yield TextArtifact(value=event.token)
elif isinstance(event, ActionChunkEvent):
action_str = action_gen.send(event)

Check warning on line 73 in griptape/utils/stream.py

View check run for this annotation

Codecov / codecov/patch

griptape/utils/stream.py#L73

Added line #L73 was not covered by tests
if action_str is not None:
Expand Down
1 change: 0 additions & 1 deletion tests/unit/events/test_action_chunk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_token(self, action_chunk_event):
assert action_chunk_event.tag == "foo"
assert action_chunk_event.name == "bar"
assert action_chunk_event.path == "baz"
assert str(action_chunk_event) == "bar.baz (foo) foo bar"

def test_to_dict(self, action_chunk_event):
assert action_chunk_event.to_dict()["partial_input"] == "foo bar"
1 change: 0 additions & 1 deletion tests/unit/events/test_text_chunk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def text_chunk_event(self):

def test_token(self, text_chunk_event):
assert text_chunk_event.token == "foo bar"
assert str(text_chunk_event) == "foo bar"

def test_to_dict(self, text_chunk_event):
assert text_chunk_event.to_dict()["token"] == "foo bar"

0 comments on commit c9d8b3a

Please sign in to comment.