-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New streaming events, EventListener
listen on parent types
#1266
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
c88058c
to
310e8e0
Compare
EventListener
listen on parent types
EventBus.add_event_listeners( | ||
[ | ||
EventListener( | ||
lambda e: print(cast(CompletionChunkEvent, e).token, end="", flush=True), | ||
event_types=[CompletionChunkEvent], | ||
lambda e: print(e.token, end="", flush=True), | ||
event_types=[TextChunkEvent], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should update this to include ActionChunkEvent
s as well since the agent uses Tools.
griptape/utils/stream.py
Outdated
yield TextArtifact(value=json.dumps(json.loads(action_str), indent=2)) | ||
action_str = ": " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's print the body on a new line instead of same line with :
. More consistent with non-streaming output.
griptape/utils/stream.py
Outdated
json.loads(action_str) | ||
yield TextArtifact(value=json.dumps(json.loads(action_str), indent=2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessarily parsing twice.
Makefile
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
def action_chunk_listener(event: ActionChunkEvent) -> None: | ||
if event.tag is not None and event.name is not None and event.path is not None: | ||
print(f"{event.name}.{event.tag} ({event.path}) ", end="", flush=True) | ||
if event.partial_input is not None: | ||
print(event.partial_input, end="", flush=True) | ||
|
||
|
||
EventBus.add_event_listeners( | ||
[ | ||
EventListener( | ||
lambda e: print(e.token, end="", flush=True), | ||
event_types=[TextChunkEvent], | ||
), | ||
EventListener( | ||
action_chunk_listener, | ||
event_types=[ActionChunkEvent], | ||
), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simplified now that we have __str__
on the events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
events_3.py
is the simplified version of this. this is an example showing how to listen on the sub event types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can still show listening on sub-types while using the str
method right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tis possible
def __str__(self) -> str: | ||
return self.token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test pls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
Describe your changes
EventListener
to listen on parent types.BaseChunkEvent
ActionChunkEvent
andTextChunkEvent
CompletionChunkEvent
Issue ticket number and link
📚 Documentation preview 📚: https://griptape--1266.org.readthedocs.build//1266/