The replicate.run method provides a nice way of running a prediction and getting its output with a single line of code:
const output = await replicate.run(identifier, options, progress);
That's nice if I only want the prediction output. But what if I want the whole prediction object? For example, maybe I want to know the prediction id, or see how long the prediction took to run. In this case, the best option is this:
let prediction = await replicate.predictions.create({ version, input })
prediction = await replicate.wait(prediction);
That works, but it's not ideal for a few reasons:
- It's more code. No longer a glamorous one-liner.
- The fact that
replicate.prediction.create is itself an async function makes me think that maybe I'm awaiting its completion too, when in fact I'm actually just awaiting the empty shell of a prediction.
- The
wait call is on the replicate object, rather than on the prediction instance itself. This is confusing.
- I can't make the prediction a
const because I have to re-assign it when I call wait. It feels weird to create a thing and then overwrite it entirely, especially in the age of JavaScript constants.
- I would probably always have to look at the docs to get this right.
How can we make this better? My off-the-cuff idea is a wait option on the replicate.predictions.create method:
const prediction = await replicate.predictions.create({ version, input, wait: true })
What do folks think of that? Open to ideas here.
cc @replicate/product @replicate/hackers
The
replicate.runmethod provides a nice way of running a prediction and getting its output with a single line of code:That's nice if I only want the prediction output. But what if I want the whole prediction object? For example, maybe I want to know the prediction id, or see how long the prediction took to run. In this case, the best option is this:
That works, but it's not ideal for a few reasons:
replicate.prediction.createis itself an async function makes me think that maybe I'm awaiting its completion too, when in fact I'm actually just awaiting the empty shell of a prediction.waitcall is on thereplicateobject, rather than on thepredictioninstance itself. This is confusing.constbecause I have to re-assign it when I callwait. It feels weird to create a thing and then overwrite it entirely, especially in the age of JavaScript constants.How can we make this better? My off-the-cuff idea is a
waitoption on thereplicate.predictions.createmethod:What do folks think of that? Open to ideas here.
cc @replicate/product @replicate/hackers