replicate-elixir icon indicating copy to clipboard operation
replicate-elixir copied to clipboard

`webhook_events_filter` not registering in `Replicate.Predictions.create`

Open mvkvc opened this issue 1 year ago • 0 comments

I am working on an app with webhooks where I only want to get the result when complete. I tried to submit the filter but I am still receiving every update in a new webhook call. Here is the code when calling:

Replicate.Predictions.create(
  version,
  %{
    prompt: prompt,
    max_new_tokens: 512,
    temperature: 0.01,
    prompt_template: ""
  },
  webhook_url,
  nil,
  ["completed"]
)

Here is the function signature:

iex(1)> h Replicate.Predictions.create

def create(version, input, webhook \\ nil, webhook_completed \\ nil, webhook_event_filter \\ nil, stream \\ nil)

I have switched to the HTTP API and it is working as expected:

body = %{
  "model" => Application.fetch_env!(:replicate, :replicate_model_name),
  "version" => Application.fetch_env!(:replicate, :replicate_model_version),
  "input" => %{
    "prompt" => prompt,
    "max_new_tokens" => 512,
    "temperature" => 0.01,
    "prompt_template" => ""
  },
  "webhook" => webhook_url,
  "webhook_events_filter" => ["completed"]
}

headers = %{
  "Content-Type" => "application/json",
  "Authorization" => "Token #{Application.fetch_env!(:replicate, :replicate_api_token)}"
}

Req.post("https://api.replicate.com/v1/predictions", body: Jason.encode!(body), headers: headers)

However, it is unclear why this works as the entries for webhook and webhook_events_filter are the same. Happy to contribute to the docs if this is not a bug and I am holding it wrong as it could be confusing for others as well.

mvkvc avatar Feb 21 '24 11:02 mvkvc