An Unofficial Rust client for Replicate. Provides a type-safe interface by deserializing API responses into Rust structs.
Getting Started
Add replicate_rust
to Cargo.toml
:
[]
= "0.0.3"
Grab your token from replicate.com/account and set it as an environment variable:
Here's an example using replicate_rust
to run a model.
use~ ;
let config = default;
let replicate = new;
// Construct the inputs.
let mut inputs = new;
inputs.insert;
let version = String from;
// Run the model.
let result = replicate.run;
// Print the result.
match result
// Some(Array [String("https://pbxt.replicate.delivery/QLDGe2rXuIQ9ByMViQEXrYCkKfDi9I3YWAzPwWsDZWMXeN7iA/out-0.png")])```
Usage
See the reference docs for detailed API documentation.
Examples
Run a model in the background
You can start a model and run it in the background:
let config = default;
let replicate = new;
// Construct the inputs.
let mut inputs = new;
inputs.insert;
let version = String from;
// Run the model.
let mut prediction = replicate.predictions.create;
println!
// 'starting'
prediction.reload
println!
// 'processing'
println!
// Some("Using seed: 3599
// 0%| | 0/50 [00:00<?, ?it/s]
// 4%|▍ | 2/50 [00:00<00:04, 10.00it/s]
// 8%|▊ | 4/50 [00:00<00:03, 11.56it/s]
// ")
prediction.wait
println!
// 'succeeded'
match prediction.wait
// Success : Some(Array [String("https://pbxt.replicate.delivery/QLDGe2rXuIQ9ByMViQEXrYCkKfDi9I3YWAzPwWsDZWMXeN7iA/out-0.png")])
Cancel a prediction
You can cancel a running prediction:
let config = default;
let replicate = new;
// Construct the inputs.
let mut inputs = new;
inputs.insert;
let version = String from;
// Run the model.
let mut prediction = replicate.predictions.create;
println!
// 'starting'
prediction.cancel
prediction.reload
println!
// 'cancelled'
List predictions
You can list all the predictions you've run:
match replicate.predictions.list
// Success : ListPredictions { ... }
Get model Information
match replicate.models.get
;
// Success : GetModel { ... }
Get Versions List
match replicate
.models
.versions
.list
;
// Success : ListModelVersions { ... }
Get Model Version Information
match replicate.models.versions.get
// Success : GetModelVersion { ... }
Get Collection Information
match replicate.collections.get
// Success : GetCollectionModels { ... }
Get Collection Lists
match replicate.collections.list
// Success : ListCollectionModels { ... }