Struct replicate_rust::prediction::Prediction
source · pub struct Prediction {
pub parent: Config,
}
Fields§
§parent: Config
Implementations§
source§impl Prediction
impl Prediction
sourcepub fn create<K: Serialize, V: Serialize>(
self,
version: String,
inputs: HashMap<K, V>
) -> PredictionClient
pub fn create<K: Serialize, V: Serialize>( self, version: String, inputs: HashMap<K, V> ) -> PredictionClient
Create a new prediction, by passing in the model version and inputs to PredictionClient. PredictionClient contains the necessary methods to interact with the prediction such as reload, cancel and wait.
Example
use replicate_rust::{Replicate, config::Config};
let config = Config::default();
let replicate = Replicate::new(config);
// Construct 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 mut prediction = replicate.predictions.create(version, inputs);
println!("Prediction : {:?}", prediction.status);
// Refetch the prediction using the reload method.
prediction.reload();
println!("Prediction : {:?}", prediction.status);
// Wait for the prediction to complete (or fail).
match prediction.wait() {
Ok(result) => println!("Success : {:?}", result.output),
Err(e) => println!("Error : {}", e),
}
sourcepub fn list(&self) -> Result<ListPredictions, Box<dyn Error>>
pub fn list(&self) -> Result<ListPredictions, Box<dyn Error>>
List all predictions executed in Replicate by the user.
Example
use replicate_rust::{Replicate, config::Config};
let config = Config::default();
let replicate = Replicate::new(config);
match replicate.predictions.list() {
Ok(result) => println!("Success : {:?}", result),
Err(e) => println!("Error : {}", e),
};
sourcepub fn get(&self, id: String) -> Result<GetPrediction, Box<dyn Error>>
pub fn get(&self, id: String) -> Result<GetPrediction, Box<dyn Error>>
Get a prediction by passing in the prediction id. The prediction id can be obtained from the PredictionClient struct.
Example
use replicate_rust::{Replicate, config::Config};
let config = Config::default();
let replicate = Replicate::new(config);
match replicate.predictions.get(String::from("rrr4z55ocneqzikepnug6xezpe")) {
Ok(result) => println!("Success : {:?}", result),
Err(e) => println!("Error : {}", e),
};
Trait Implementations§
source§impl Clone for Prediction
impl Clone for Prediction
source§fn clone(&self) -> Prediction
fn clone(&self) -> Prediction
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 Prediction
impl Send for Prediction
impl Sync for Prediction
impl Unpin for Prediction
impl UnwindSafe for Prediction
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