-
Notifications
You must be signed in to change notification settings - Fork 13
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 api #91
Conversation
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.
I think I follow, and it seems good to me. What about this implementation is feeling scrappy to you?
stream.go
Outdated
case SSETypeOutput: | ||
io.WriteString(writer, event.Data()) | ||
case SSETypeDone: | ||
writer.Close() | ||
return |
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 error handling be useful here?
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.
SSETypeDone isn't an error case, so I'm not sure what you mean?
5656e2c
to
965e0ef
Compare
This is a substantial refactoring: - I've changed the retry logic from making a recursive call to using a loop - I've started using the existing r.options.retryPolicy to define retry behavior - I've extracted a common streamEventsTo function, used by both streamTextTo and streamFilesTo, so that retry behavior is defined in one place
Oof I think this is leaking goroutines https://github.com/replicate/synthetics/pull/108#issuecomment-2405810904 I'll dig in to this tomorrow. |
b615aa9
to
84460b1
Compare
The eventsource one leaks goroutines if you don't hold it just right.
84460b1
to
32241c2
Compare
This no longer leaks 🎉 |
No goroutines! Only Readers!
Again, no goroutines! Only Readers!
27e45f7
to
abaf8f3
Compare
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.
I think this looks really nice now. Super clear and easy to follow, nicely factored, well tested. Love it. If it works, too, I say ship it!
This adds functions StreamPredictionText() and StreamPredictionFiles() that stream output from models that return iterators of strings or files, respectively.
This is scrappy but functional. I'd like to discuss the approach and see if people think this is sensible.