pub struct PredictionClient {
pub parent: Config,
pub id: String,
pub version: String,
pub urls: PredictionsUrls,
pub created_at: String,
pub status: PredictionStatus,
pub input: HashMap<String, Value>,
pub error: Option<String>,
pub logs: Option<String>,
}
Expand description
Helper struct for the Prediction struct. Used to create a prediction, reload for latest info, cancel it and wait for prediction to complete.
Fields§
§parent: Config
Holds a reference to a Configuration struct, which contains the base url, auth token among other settings.
id: String
Unique identifier of the prediction
version: String
§urls: PredictionsUrls
§created_at: String
§status: PredictionStatus
§input: HashMap<String, Value>
§error: Option<String>
§logs: Option<String>
Implementations§
source§impl PredictionClient
impl PredictionClient
sourcepub fn create<K: Serialize, V: Serialize>(
rep: Config,
version: &str,
inputs: HashMap<K, V>
) -> Result<PredictionClient, ReplicateError>
pub fn create<K: Serialize, V: Serialize>( rep: Config, version: &str, inputs: HashMap<K, V> ) -> Result<PredictionClient, ReplicateError>
Run the prediction of the model version with the given input
Example
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 = "stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478";
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs)?;
sourcepub fn reload(&mut self) -> Result<(), ReplicateError>
pub fn reload(&mut self) -> Result<(), ReplicateError>
Returns the latest info of the prediction
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 = "stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478";
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs)?;
// Reload the prediction to get the latest info and logs
prediction.reload()?;
println!("Prediction : {:?}", prediction.status);
sourcepub fn cancel(&mut self) -> Result<(), ReplicateError>
pub fn cancel(&mut self) -> Result<(), ReplicateError>
Cancel the prediction
Example
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 = "stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478";
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs)?;
// Cancel the prediction
prediction.cancel()?;
// Wait for the prediction to complete (or fail).
let result = prediction.wait()?;
println!("Result : {:?}", result);
sourcepub fn wait(&self) -> Result<GetPrediction, ReplicateError>
pub fn wait(&self) -> Result<GetPrediction, ReplicateError>
Blocks until the predictions are ready and returns the predictions
Example
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 = "stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478";
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs)?;
// Wait for the prediction to complete (or fail).
let result = prediction.wait()?;
println!("Result : {:?}", result);
Trait Implementations§
source§impl Clone for PredictionClient
impl Clone for PredictionClient
source§fn clone(&self) -> PredictionClient
fn clone(&self) -> PredictionClient
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for PredictionClient
impl Send for PredictionClient
impl Sync for PredictionClient
impl Unpin for PredictionClient
impl UnwindSafe for PredictionClient
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more