{"id":17595356,"url":"https://github.com/anasfik/replicate","last_synced_at":"2025-04-10T23:21:28.831Z","repository":{"id":65763486,"uuid":"598850873","full_name":"anasfik/replicate","owner":"anasfik","description":"A community-maintained Dart client package for Replicate.com, this package let you interact with Replicate.com APIs and create predictions from the available machine learning models.","archived":false,"fork":false,"pushed_at":"2024-04-25T07:59:44.000Z","size":1725,"stargazers_count":10,"open_issues_count":6,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T08:59:55.205Z","etag":null,"topics":["ai","api","artificial-intelligence","cloud-based","dart","dart-package","machine-learning","replicate","replicate-data","stable-diffusion"],"latest_commit_sha":null,"homepage":"https://replicate.com/","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anasfik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-07T23:37:31.000Z","updated_at":"2025-01-29T22:37:24.000Z","dependencies_parsed_at":"2024-10-22T16:16:26.140Z","dependency_job_id":null,"html_url":"https://github.com/anasfik/replicate","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anasfik%2Freplicate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anasfik%2Freplicate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anasfik%2Freplicate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anasfik%2Freplicate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anasfik","download_url":"https://codeload.github.com/anasfik/replicate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313168,"owners_count":21082812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","artificial-intelligence","cloud-based","dart","dart-package","machine-learning","replicate","replicate-data","stable-diffusion"],"created_at":"2024-10-22T07:54:51.344Z","updated_at":"2025-04-10T23:21:28.814Z","avatar_url":"https://github.com/anasfik.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Replicate Dart Client\n\nA community-maintained Dart client package for Replicate.com, this package let you interact with Replicate.com APIs and create predictions from the available machine learning models.\n\n## Key Features.\n\n- Easy to call methods for creating, Getting, Cancelling one prediction, and getting a pagination lists of predictions used.\n- `Stream` availability for listening to a predictions changes in realtime.\n- Dynamic inputs for the possibility to use any model available on Replicate.com flexibly.\n- Wrappers around response fields, for a better developer experience.\n- Easy to configure, and set your settings using this library.\n\n# Full Documentation\n\nYou can check the Full Documentation of this library [from here](https://pub.dev/documentation/replicate/latest/).\n\n# Usage\n\n### Authentication\n\nBefore making any requests, you should set your API key so it will be used to make requests to your account on `Replicate.com`.\n\n```dart\n  Replicate.apiKey = \"\u003cYOUR_API_KEY\u003e\";\n```\n\n###### **Recommendation**:\n\nit's better to load your api key from a `.env` file, you can do this in Dart using [dotenv](https://pub.dev/packages/dotenv) package.\n\n\u003cbr\u003e\n\n## Create Prediction\n\nYou can call this to start creating a new prediction for the version and input you will provide, since the models can take some time to run, This `output` will not be available immediately, it will return a `Prediction` with the returned response from Replicate.com, with a `status` set to the prediction status at this point:\n\n```dart\nPrediction prediction = await Replicate.instance.predictions.create(\n    version: \"\u003cMODEL_VERSION\u003e\",\n    input: {\n      \"field_name\": \"\u003cfield_value\u003e\",\n    },\n  );\n```\n\nNote that `input` takes a `Map\u003cString, dynamic\u003e` as a value since every model has its input accepted fields.\n\nif you want to create a new prediction for a model that accepts a file field(s), you need just to set that field(s) value to either a network url , or the base64 of that file.\n\n\u003cbr\u003e\n\n## Get Prediction\n\nif you need to get a Prediction at a specific point in time, you can call the `Replicate.instance.predictions.get()` method, it will return a new `Prediction` object with the requested prediction data:\n\n```dart\nPrediction prediction = await Replicate.instance.predictions.get(\n    id: \"\u003cPREDICTION_ID\u003e\",\n);\n\nprint(prediction); // ...\n```\n\nA `Prediction` object is a container for prediction progress data (status, logs, output, metrics... ) requested from your `Replicate.com` dashboard.\n\nWhen a `Prediction` is Terminated, the `metrics` property will have a `predictTime` property with the amount of CPU or GPU time, in seconds, that this prediction used while running. This is the time you're billed for, and it doesn't include time waiting for the prediction to start.\n\nA `Prediction` is considered terminated when the `status` property is one of :\n\n- `PredictionStatus.succeeded`\n- `PredictionStatus.canceled`\n- `PredictionStatus.failed`\n\nYou might want to give a quick look over [Get Prediction](https://replicate.com/docs/reference/http#get-prediction).\n\n\u003cbr\u003e\n\n## Cancel Prediction\n\nYou can cancel a running prediction by calling `Replicate.instance.predictions.cancel()` :\n\n```dart\nfinal canceledPrediction = await Replicate.instance.predictions.cancel(\n  id: \"\u003cPREDICTION_ID\u003e\",\n);\n```\n\n\u003cbr\u003e\n\n## Get list of predictions\n\nYou can get a paginated list of predictions that you've created with your account by calling :\n\n```dart\nPaginatedPredictions predictionsPageList = await Replicate.instance.predictions.list();\n\nprint(predictionsPageList.results); // ...\n```\n\nThis includes predictions created from the API and the Replicate website. Returns 100 records per page.\n\nYou can check before requesting the next/previous pagination lists:\n\n```dart\nif (predictionsPageList.hasNextPage) {\n  PaginatedPredictions next = await predictionsPageList.next();\n  print(next.results); // ...\n}\nif (predictionsPageList.hasPreviousPage) {\n  PaginatedPredictions prev = await predictionsPageList.previous();\n  print(prev.results); // ...\n}\n```\n\n\u003cbr\u003e\n\n## Listening to prediction changes.\n\nAfter Creating a new prediction with [Create Prediction](#create-prediction), while it is running, you can get a `Stream` of its changes in real-time by calling:\n\n```dart\nStream\u003cPrediction\u003e predictionStream = Replicate.instance.predictions.snapshots(\n    id: \"\u003cPREDICTION_ID\u003e\",\n);\n\npredictionStream.listen((Prediction prediction) {\n   print(prediction.status); // ...\n});\n\n```\n\nBy default, every time the status of the prediction changes, a new `Prediction` will be emitted to the `predictionStream`, but you can change and configure this behavior to meet your specific needs by specifying a `pollingInterval`, `shouldTriggerOnlyStatusChanges`, `stopPollingRequestsOnPredictionTermination`..\n\nThis functionality is based on polling request as it's recommended by [replicate from here](https://replicate.com/docs/reference/http#create-prediction).\n\n\u003cbr\u003e\n\n## I don't want to listen to changes by `Stream`.\n\nWell, Replicate.com offers also notifying with webhook feature.\n\nwhile [creating a prediction](#create-prediction), you can set the `webhookCompleted` property to your HTTPS URL which will receive the response when the prediction is completed:\n\n```dart\nPrediction prediction = await Replicate.instance.predictions.create(\n    version: \"\u003cMODEL_VERSION\u003e\",\n    input: {\n      \"field_name\": \"\u003cfield_value\u003e\",\n    },\n    webhookCompleted: \"\u003cYOUR_HTTPS_URL\u003e\", // add this\n  );\n```\n\nlearn more about the webhook feature [from here](https://replicate.com/docs/reference/http#create-prediction--webhook_comple)\n\n\u003cbr\u003e\n\n## Get Model\n\nGets a single model, based on it's owner and name, and returns it as a [ReplicateModel].\n\n```dart\nReplicateModel model = await Replicate.instance.models.get(\n  modelOwner: \"replicate\",\n  modelNme: \"hello-world\",\n);\n\nprint(model);  // ...\nprint(model.url);  // ...\nprint(model.owner); // replicate\n```\n\n\u003cbr\u003e\n\n## Get a list of model versions\n\nGets a model's versions as a paginated list, based on it's owner and name.\n\nif you want to get a specific version, check [Get A Model Version](#get-a-model-version).\n\nYou can load the next and previous pagination list of a current on, by using `next()` and `previous()` method.\n\nif no next or previous pages exists for a pagination list, a `NoNextPageException` or `NoPreviousPageException` will be thrown.\n\nFor avoiding those exceptions at all, you can check for the next and previos pages existence using the `hasNextPage` and `hasPreviousPage` :\n\n```dart\nPaginatedModels modelVersions = await Replicate.instance.model.versions(\n modelOwner: \"replicate\",\n modelNme: \"hello-world\",\n);\n\nprint(modelVersions.results); // ...\n\n// loads the next page if it exists\nif (modelVersions.hasNextPage) {\n PaginatedModels nextPage = await modelVersions.next();\n\n print(nextPage.results); // ...\n}\n```\n\n\u003cbr\u003e\n\n## Get A Model Version\n\nGets a single model version, based on it's owner, name, and version id.\n\nif you want to get a list of versions, check [Get a list of model versions](#get-a-list-of-model-versions).\n\n```dart\nPaginationModel modelVersion = await Replicate.instance.models.version(\n modelOwner: \"replicate\",\n modelNme: \"hello-world\",\n versionId: \"5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa\",\n);\n\nprint(modelVersion.id); // ...\n```\n\n\u003cbr\u003e\n\n## Delete A Model.\n\nDelete a model version and all associated predictions, including all output files.\n\n```dart\nawait Replicate.instance.models.delete(\n modelOwner: \"/* Owner */\",\n modelNme: \"/* Model Name */\",\n versionId: \"/* Version Id */\",\n);\n```\n\nif the file os deleted succefully, nothing will happen actually, so you should expect that the model is deleted if none happens in your code, However, when something goes wrong ( if you try to delete a model which you don't own, a `ReplicateException` will be thrown with the error message ).\n\n\u003cbr\u003e\n\n## Get a collection of models.\n\nLoads a collection of models.\n\n```dart\nModelsCollection collection = await Replicate.instance.models.collection(\ncollectionSlug: \"super-resolution\",\n);\n\n  print(collection.name); // super resolution\n  print(collection.models); // ...\n```\n\n\u003cbr\u003e\n\n# Error Handling\n\n\u003cbr\u003e\n\n### ReplicateException\n\nThis exception will be thrown when there is an error from the replicate.com end, as example when you hit the rate limit you will get a `ReplicateException` with the message and the status code of the erorr:\n\n```dart\ntry {\n// ...\n\n} on ReplicateException carch(e) {\nprint(e.message);\nprint(e.statusCode);\n}\n```\n\n\u003cbr\u003e\n\n### NoNextPageException, NoPreviousPageException\n\nThese are special and limited exception when working with [Get A List Of Model Versions](#get-a-list-of-model-versions), when you try to get the `next()` or `previous()` of a pagintaed list that don't exist, one of those exceptions will be thrown, but the way to avoid them totally are included in the documentation.\n\n```dart\ntry {\nPaginatedModels firstPage = // ...\npage.previous(); // obviously, there is no previous for first page, right?\n\n} on NoPreviousPageException catch(e) {\nprint(// no next for this paginated list.);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanasfik%2Freplicate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanasfik%2Freplicate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanasfik%2Freplicate/lists"}