-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add events util #1480
base: main
Are you sure you want to change the base?
Add events util #1480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,18 @@ Handler 1 <class 'griptape.events.finish_structure_run_event.FinishStructureRunE | |
Handler 2 <class 'griptape.events.finish_structure_run_event.FinishStructureRunEvent'> | ||
``` | ||
|
||
## Stream Iterator | ||
|
||
You can use `Structure.run_stream()` for streaming Events from the `Structure` in the form of an iterator. | ||
|
||
!!! tip | ||
|
||
Set `stream=True` on your [Prompt Driver](../drivers/prompt-drivers.md) in order to receive completion chunk events. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love to see this requirement be inferred based on Structure usage rather than needing it to be set in the constructor. Obviously out of scope, but writing it down until I have time to fill out an issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, we need a better way for framework components to broadcast that they publish stream-like events. |
||
|
||
```python | ||
--8<-- "docs/griptape-framework/misc/src/events_streaming.py" | ||
``` | ||
|
||
## Context Managers | ||
|
||
You can also use [EventListener](../../reference/griptape/events/event_listener.md)s as a Python Context Manager. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from griptape.events import BaseEvent | ||
from griptape.structures import Agent | ||
|
||
agent = Agent() | ||
|
||
for event in agent.run_stream("Hi!", event_types=[BaseEvent]): # All Events | ||
print(type(event)) |
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.
Would prefer a
EventStream
util likeStream
that currently exists and punt more core API changes to the Structure api to a later time, but not going to block the PR based on that.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.
The downside of this approach is that
EventStream
would need to support anything that might need this functionality (Structures, Tasks, Drivers, Tools, etc).I'm just as nervous about modifying
Structure
's API, but this implementation does at least seem consistent with other similar frameworks.