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

Feature request: prediction streaming #42

Open
daneden opened this issue Jul 25, 2023 · 2 comments
Open

Feature request: prediction streaming #42

daneden opened this issue Jul 25, 2023 · 2 comments

Comments

@daneden
Copy link

daneden commented Jul 25, 2023

Hi there! I’ve recently started playing with Replicate in SwiftUI and this library has been super helpful.

In my previous custom implementation of the Replicate HTTP API, I was doing some manual polling to get a stream of updates in predictions:

// Illustrative pseudocode
Task {
  while prediction.completedAt == nil {
    do {
      try await Task.sleep(nanoseconds: 1_000_000_000)
      prediction = try await fetchPrediction(prediction.id)
    } catch {
      print(error)
    }
  }
}

// 1 second
print(prediction.output) // ["Hello", "!", " "]

// 2 seconds
print(prediction.output) // ["Hello", "!", " ", "As", " ", "a", " ", "helpful", ...]

It'd be great if this library included a polling/streaming method alongside the wait method, especially for chat-like models.

@mattt
Copy link
Member

mattt commented Jul 31, 2023

Hi @daneden. That's a great idea! We recently added support for streaming prediction output to Replicate. #41 added an overload to Client.createPrediction that accepts a stream parameter. When set to true, the created prediction will include a "stream" key in its urls property.

My next step is to create a Swift implementation of EventSource that conforms to AsyncSequence and you could iterate over directly.

@tianye2856
Copy link

Please support Streaming and EventSource as the Replicate JavaScript code you provided here.
https://github.com/replicate/replicate-javascript#streaming

Now even that you have a stream parameter, it doesn't make any sense.
Because we still need to make the stream logic code by ourself.

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

No branches or pull requests

3 participants