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

Error while creating prediction #4

Open
Borys520 opened this issue Jul 6, 2023 · 7 comments
Open

Error while creating prediction #4

Borys520 opened this issue Jul 6, 2023 · 7 comments

Comments

@Borys520
Copy link

Borys520 commented Jul 6, 2023

Hi,
Thanks for the wonderful package! I am trying to create prediction but it always throws an error :

[Replicate] request started from/to: https://api.replicate.com/v1/predictions.
[Replicate] request from/to: https://api.replicate.com/v1/predictions end.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>'
#0 new Prediction.fromJson prediction.dart:75
#1 ReplicatePrediction.create. predictions.dart:62
#2 ReplicateHttpClient.post http_client.dart:54
#3 _MyHomePageState.build. main.dart:61

image

@ZYLIM0702
Copy link

Hi, do you get the solution? Can you share with me? Thanks

@DavideSantoro
Copy link

I got the same error. Did you find a solution?

@alesspalma
Copy link

same error

@ZYLIM0702
Copy link

do you guys get the solution ? I still facing the same error

@DavideSantoro
Copy link

DavideSantoro commented Aug 1, 2023

 Replicate.apiKey = dotenv.env['API_KEY']!;

 try {
   Prediction prediction = await Replicate.instance.predictions.create(
     version:
         "b96a2f33cc8e4b0aa23eacfce731b9c41a7d9466d9ed4e167375587b54db9423",
     input: {
       "prompt": "What is shown in the image?",
       "image":
           "https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg"
     },
   );
 } catch (e) {
   //nothing
 }
 await Future.delayed(Duration(seconds: 7));
 PaginatedPredictions predictionsPageList =
     await Replicate.instance.predictions.list();

 Prediction prediction = await Replicate.instance.predictions.get(
   id: predictionsPageList.results.elementAt(0).id,
 );
 print(prediction.output);

This is the code I used. You need to install the dotenv plugin and to put your Replicate API key in a .env file

@ZYLIM0702
Copy link

Hi, if I don't use dotenv, then will it still be working ? And this is my code, can you provide me ways to debug my code ?
IMG_20230802_001229.png

@bigjjjim
Copy link

bigjjjim commented Sep 27, 2023

await Future.delayed(Duration(seconds: 7));
PaginatedPredictions predictionsPageList =
await Replicate.instance.predictions.list();

Prediction prediction = await Replicate.instance.predictions.get(
id: predictionsPageList.results.elementAt(0).id,
);
print(prediction.output);

Yes this way it works, but the object prediction does return null right after creating it. Even after 20 seconds, the object created by
Prediction prediction = await Replicate.instance.predictions.create() returns null making it impossible to check with a stream or in a while loop...
What if the model takes more than the 7 seconds?

I suppose we could fetch the id from the list like you do then check the status but then my question is:

Will the prediction be added to the list even thought it is not fully completed? And will it always take less than 7 seconds to be added to this list?

Thank you for the code by the way, was really confused by this null prediction!

Edit** Actualyy, if we cannot fetch the id of the first created object directly how can we ensure we have the right prediction, given that 2 users may create a prediction at the same time!

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

5 participants