Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements basic streaming requests and a response with stream message iterator helpers.
The request interface largely mirrors the
run
andasync_run
functions, but the response is aSubstrateStreamingResponse
.The
SubstrateStreamingResponse
has 4 helper methods that return iterators:.iter()
yieldsServerSentEvent
objects.async_iter()
yieldsServerSentEvent
objects.iter_events()
yields strings formatted as Server-Sent Events.async_iter_events()
yields strings formatted as Server-Sent EventsIf the user would like to do some processing on the message objects, using the
.iter()
or.async_iter()
would allow them to access the message data as dictionaries.The
ServerSentEvent.data
property may contain the following messages:node.result
: completed the result of a node (identified bynode_id
)node.delta
: when possible, incremental chunks of output (identified bynode_id
)node.error
: any error messages encountered when running a nodegraph.result
: the completed results for the entire run (same structure as theSubstrateResponse.json
)The message data are currently dictionaries, but the structure maps to the node "Out" types (including the
ErrorOut
type). The delta messages are structured similarly, except for array fields - which are dictionaries that contain anobject
field with the valuearray.item
, anindex
field that corresponds to the index the chunk belongs to, and anitem
field when is the same structure of that array item.If the user is interested in proxying the Server-Sent Events from the Substrate server response to another client, then using
.iter_events()
or.async_iter_events()
provides convenience for passing this along to a response writer (such asStreamingResponse
from FastAPI).