anasfik / replicate

A community-maintained Dart client package for Replicate.com, this package let you interact with Replicate.com APIs and create predictions from the available machine learning models.
https://replicate.com/
MIT License
10 stars 10 forks source link

Stream is not working #5

Open devops-chatai opened 6 months ago

devops-chatai commented 6 months ago

The code snippet related to streaming isn't functioning as expected. It seems that despite using examplePredictionId, which is supposed to be the ID of the prediction generated by Replicate.instance.predictions.create, no events are being triggered.

Is it possible that streaming isn't supported? It seems that the stream codes have been commented out. I already uncomment and run the stream, however no event is never triggered.

  Stream<Prediction> stream = Replicate.instance.predictions.snapshots(
      id: examplePredictionId!,
      pollingInterval: Duration(seconds: 2),
      shouldTriggerOnlyStatusChanges: true,
      stopPollingRequestsOnPredictionTermination: true,
    );

  expect(stream, isA<Stream<Prediction>>());

  stream.listen((event) {
    print('Received event: $event');
    expect(event, isA<Prediction>());
    expect(event.id, examplePredictionId!);
    print(event.status);
  }, onError: (e) {
    print('Error in stream: $e');
    fail('should not throw an exception');
  }, onDone: () async {
    print('Stream closed');
    print('done');
    FetchedPrediction prediction = await Replicate.instance.predictions.get(
      id: examplePredictionId!,
    );
    final imageUrlList = prediction.output;
    await saveImageFromUrl(imageUrlList, 'outputs');

  });