Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created March 14, 2023 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anotherjesse/5ef893860ab1dd513b9f5d4afef0c7eb to your computer and use it in GitHub Desktop.
Save anotherjesse/5ef893860ab1dd513b9f5d4afef0c7eb to your computer and use it in GitHub Desktop.
polling vs webhooks - replicate-python

polling

model = replicate.models.get("replicate/hello-world")
version = model.versions.get("5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa")
inputs = {
  "text": "world",
}
output = version.predict(**inputs)

webhook

model = replicate.models.get("replicate/hello-world")
version = model.versions.get("5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa")
prediction = replicate.predictions.create(
    version=version,
    input={"text":"world"},
    webhook_completed="https://webhook.site/anotherjesse")

webhook response

{
  "id": "vv7g26gegnft3ddo4uer4nfmju",
  "version": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
  "input": {
    "text": "world"
  },
  "logs": "",
  "output": "hello world",
  "error": null,
  "status": "succeeded",
  "created_at": "2023-03-14T22:03:13.989417Z",
  "started_at": "2023-03-14T22:03:14.069854Z",
  "completed_at": "2023-03-14T22:03:14.131674Z",
  "webhook": "https://webhook.site/anotherjesse",
  "webhook_events_filter": [
    "completed"
  ],
  "urls": {
    "cancel": "https://api.replicate.com/v1/predictions/vv7g26gegnft3ddo4uer4nfmju/cancel",
    "get": "https://api.replicate.com/v1/predictions/vv7g26gegnft3ddo4uer4nfmju"
  },
  "metrics": {
    "predict_time": 0.06182
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment