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
§id: String
§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: String,
inputs: HashMap<K, V>
) -> Result<PredictionClient, Box<dyn Error>>
pub fn create<K: Serialize, V: Serialize>( rep: Config, version: String, inputs: HashMap<K, V> ) -> Result<PredictionClient, Box<dyn Error>>
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 = String::from("stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478");
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs);
sourcepub fn reload(&mut self) -> Result<(), Box<dyn Error>>
pub fn reload(&mut self) -> Result<(), Box<dyn Error>>
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 = String::from("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().unwrap();
println!("Prediction : {:?}", prediction.status);
sourcepub fn cancel(&mut self) -> Result<(), Box<dyn Error>>
pub fn cancel(&mut self) -> Result<(), Box<dyn Error>>
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 = String::from("stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478");
// Create a new prediction
let mut prediction = replicate.predictions.create(version, inputs);
// Cancel the prediction
prediction.cancel().unwrap();
// Wait for the prediction to complete (or fail).
let result = prediction.wait().unwrap();
println!("Result : {:?}", result);
sourcepub fn wait(self) -> Result<GetPrediction, Box<dyn Error>>
pub fn wait(self) -> Result<GetPrediction, Box<dyn Error>>
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 = String::from("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().unwrap();
println!("Result : {:?}", result);
Auto 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