Skip to content
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

Merged
merged 19 commits into from
Oct 11, 2024
Merged

New streaming api #91

merged 19 commits into from
Oct 11, 2024

Conversation

philandstuff
Copy link
Contributor

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.

Copy link

@meatballhat meatballhat left a 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
Comment on lines 215 to 214
case SSETypeOutput:
io.WriteString(writer, event.Data())
case SSETypeDone:
writer.Close()
return

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?

Copy link
Contributor Author

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?

@philandstuff philandstuff changed the base branch from simplify-streaming to main October 10, 2024 14:10
@philandstuff philandstuff marked this pull request as ready for review October 10, 2024 14:10
@philandstuff philandstuff requested review from nickstenning and a team October 10, 2024 14:10
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
@philandstuff
Copy link
Contributor Author

Oof I think this is leaking goroutines https://github.com/replicate/synthetics/pull/108#issuecomment-2405810904 I'll dig in to this tomorrow.

The eventsource one leaks goroutines if you don't hold it just right.
@philandstuff
Copy link
Contributor Author

This no longer leaks 🎉

No goroutines! Only Readers!
Again, no goroutines! Only Readers!
ensure we check the result of connect()
Copy link
Contributor

@nickstenning nickstenning left a 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!

@philandstuff philandstuff merged commit d30ddaf into main Oct 11, 2024
3 checks passed
@philandstuff philandstuff deleted the new-streaming branch October 11, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants