Crate replicate_rust
source ·Expand description
Rust Client for interacting with the Replicate API.
Example
In this example we will run a model that generates a caption for an image using the Stable Diffusion model.
use replicate::Replicate;
// Reading the API key from an environment variable.
let api_key = std::env::var("REPLICATE_API_TOKEN").unwrap_or_else(|_| {
eprintln!("REPLICATE_API_TOKEN not set");
std::process::exit(1)
});
// Create a new Replicate client.
let replicate = Replicate::new(api_key)
// 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.
- The client module contains the Client struct, which is used to initialize settings for the API client. It contains the
API token
, theuser agent
and thebase url
. - Used to interact with the Collection Endpoints.
- 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.