Crate replicate_rust
source ·Expand description
Rust Client for interacting with the Replicate API. Provides a type-safe interface by deserializing API responses into Rust structs.
Getting Started
Add replicate_rust
to your Cargo.toml
file.
[dependencies]
replicate_rust = "0.0.3"
Example
In this example we will run a model that generates a caption for an image using the Stable Diffusion model.
use replicate_rust::{Replicate, config::Config};
let config = Config::default();
let replicate = Replicate::new(config);
// Creating the inputs
let mut inputs = std::collections::HashMap::new();
inputs.insert("prompt", "a 19th century portrait of a wombat gentleman");
let version = String::from("stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478");
// Run the model.
let result = replicate.run(version, inputs);
// Print the result
match result {
Ok(result) => println!("Success : {:?}", result.output),
Err(e) => println!("Error : {}", e),
}
Modules
- This module contains the definition of the API responses by the Replicate API. The responses the documented in the HTTP API reference.
- Used to interact with the Collection Endpoints.
- The config module contains the Config struct, which is used to initialize configuration for the API. Currently contains the
API token
, theuser agent
and thebase url
. - Used to interact with the Model Endpoints.
- Used to interact with the Prediction Endpoints.
- Helper struct for the prediction struct
- Helper struct for the prediction struct. Used to retry pooling the api for latest prediction status until it is completed.
- Used to interact with the Training Endpoints.
- Used to interact with the Model Versions Endpoints.