-
Notifications
You must be signed in to change notification settings - Fork 0
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
Introduces Streaming #80
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
liamgriffiths
force-pushed
the
liam/streaming
branch
from
June 5, 2024 20:20
0277873
to
37bf9be
Compare
…own" future types
liamgriffiths
changed the title
Experimental example of streaming nodes
Introduces Streaming
Jun 7, 2024
0thernet
reviewed
Jun 7, 2024
|
||
if (response.ok) { | ||
setOutput(""); | ||
const stream = await sb.streaming.fromSSEResponse(response); |
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.
neat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 streaming in the SDK!
The streaming interface largely mirrors the non-streaming one. Instead of
substrate.run
we havesubstrate.stream
which returns aSubstrateStreamingResponse
(vs aSubstrateResponse
).This new response object is also an async generator and can also be iterated over to read the stream messages as they are received.
In addition to using the iterator, there are two additional utilities I added in for now,
tee
andget
.tee
is useful because once a stream is consumed, it cannot be read again - however if the user would like to have multiple consumer/iterators they can usetee
to split the stream into however many they like.get
is the streaming analog tores.get
in the non-streaming interface. It filters the stream for messages that belong to a specific node and re-uses some the type inference we have so far.The server will respond with server-sent events when the request is:
x-substrate-streaming: 1
headeraccept: text/event-stream
headerThe server-sent event messages come back in a few flavors:
node.delta
- chunks of a nodes result (when possible)node.result
- the final result for a nodenode.error
- any errors encountered trying to run the nodegraph.result
- the accumulated result of the entire graphWe might also include other message types, but tbd:
node.usage
- various usage metrics for the nodegraph.error
- any graph-level errors we may encounter