View Source Replicate.Predictions (Replicate v1.3.0)

Documentation for Predictions.

Link to this section Summary

Functions

Cancels a prediction given an id or %Prediction{}.

Creates a prediction. You can optionally provide a webhook to be notified when the prediction is completed.

Gets a prediction by id.

Gets a prediction by id and fails if it doesn't exist.

Lists all the predictions you've run.

Waits for a prediction to complete.

Link to this section Functions

Cancels a prediction given an id or %Prediction{}.

examples

Examples

iex> {:ok, prediction} = Replicate.Predictions.cancel("1234")
iex> prediction.status
"canceled"

iex> model = Replicate.Models.get!("stability-ai/stable-diffusion")
iex> version = Replicate.Models.get_version!(model, "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf")
iex> {:ok, prediction} = Replicate.Predictions.create(version, %{prompt: "a 19th century portrait of a wombat gentleman"})
iex> {:ok, prediction} = Replicate.Predictions.cancel(prediction)
iex> prediction.status
"canceled"

If a prediction is completed, it cannot be canceled.

iex> model = Replicate.Models.get!("stability-ai/stable-diffusion")
iex> version = Replicate.Models.get_version!(model, "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf")
iex> {:ok, prediction} = Replicate.Predictions.create(version, %{prompt: "a 19th century portrait of a wombat gentleman"})
iex> prediction.status
"starting"
iex> {:ok, prediction} = Replicate.Predictions.wait(prediction)
iex> prediction.status
"succeeded"
# iex> {:ok, prediction} = Replicate.Predictions.cancel(prediction.id)
# iex> prediction.status
# "succeeded"
Link to this function

create(model, input, webhook \\ nil, webhook_completed \\ nil, webhook_event_filter \\ nil, stream \\ nil)

View Source

Creates a prediction. You can optionally provide a webhook to be notified when the prediction is completed.

The input parameter should be a map of the model inputs.

examples

Examples

If you're calling an Official Model, you can provide the model name and version:

iex> {:ok, prediction} = Replicate.Predictions.create("stability-ai/stable-diffusion-3", %{prompt: "a 19th century portrait of a wombat gentleman"})
iex> prediction.status
"starting"

Otherwise, provide a `%Replicate.Models.Version{}` struct:

iex> model = Replicate.Models.get!("stability-ai/stable-diffusion") iex> version = Replicate.Models.get_version!(model, "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf") iex> {:ok, prediction} = Replicate.Predictions.create(version, %{prompt: "a 19th century portrait of a wombat gentleman"}) iex> prediction.status "starting" iex> {:ok, prediction} = Replicate.Predictions.create(version, %{prompt: "a 19th century portrait of a wombat gentleman"}, "https://example.com/webhook") iex> prediction.status "starting"

Gets a prediction by id.

examples

Examples

iex> {:ok, prediction} = Replicate.Predictions.get("1234")
iex> prediction.status
"succeeded"

iex> Replicate.Predictions.get("not_a_real_id")
{:error, "Not found"}

Gets a prediction by id and fails if it doesn't exist.

## Examples

iex> prediction = Replicate.Predictions.get!("1234")
iex> prediction.id
"1234"

iex> Replicate.Predictions.get!("not_a_real_id")
** (RuntimeError) Not found

Lists all the predictions you've run.

examples

Examples

iex> Replicate.Predictions.list()
[%Prediction{
  id: "1234",
  status: "starting",
  input: %{"prompt" => "a 19th century portrait of a wombat gentleman"},
  version: "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
  output: ["https://replicate.com/api/models/stability-ai/stable-diffusion/files/50fcac81-865d-499e-81ac-49de0cb79264/out-0.png"],
  urls: %{
    "get" => "https://api.replicate.com/v1/predictions/1234",
    "cancel" => "https://api.replicate.com/v1/predictions/1234/cancel",
  }
 },
 %Prediction{
  id: "1235",
  status: "starting",
  input: %{"prompt" => "a 19th century portrait of a wombat gentleman"},
  version: "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
  output: ["https://replicate.com/api/models/stability-ai/stable-diffusion/files/50fcac81-865d-499e-81ac-49de0cb79264/out-0.png"],
  urls: %{
    "get" => "https://api.replicate.com/v1/predictions/1235",
    "cancel" => "https://api.replicate.com/v1/predictions/1235/cancel"
  }
}]

Waits for a prediction to complete.

examples

Examples

iex> model = Replicate.Models.get!("stability-ai/stable-diffusion")
iex> version = Replicate.Models.get_version!(model, "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf")
iex> {:ok, prediction} = Replicate.Predictions.create(version, %{prompt: "a 19th century portrait of a wombat gentleman"})
iex> prediction.status
"starting"
iex> {:ok, prediction} = Replicate.Predictions.wait(prediction)
iex> prediction.status
"succeeded"