diff --git a/src/client.rs b/src/client.rs index 5c117eb..185d064 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,7 +1,7 @@ use crate::{api_key, base_url}; use anyhow::anyhow; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ReplicateClient { api_key: Option<&'static str>, base_url: String, diff --git a/src/lib.rs b/src/lib.rs index e4e7b08..a2cfb2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,47 @@ +//! A simple http client for interacting with [Replicate](https://replicate.com/). +//! Provides simple async functionality for interacting with Replicate via +//! [serde](https://serde.rs) and [isahc](https://docs.rs/isahc/latest/isahc/). +//! +//! # Getting Started +//! +//! Add the following to your cargo toml +//! ```toml +//! replicate-rs = "0.2.0" +//! ``` +//! +//! # Examples +//! +//! #### Create a Prediction +//! +//! Create a prediction, and get refreshed prediction data. +//! +//! ```rust +//! use replicate_rs::client::ReplicateClient; +//! use replicate_rs::predictions::PredictionClient; +//! use serde::Serialize; +//! +//! let client = ReplicateClient::new()?; +//! let prediction_client = PredictionClient::from(client); +//! +//! #[derive(Serialize)] +//! struct HelloWorldInput { +//! text: "kyle" +//! } +//! +//! // Create the prediction +//! let prediction = prediction_client.create("replicate", "hello-world", prediction_input).await?; +//! +//! // Refresh the data +//! prediction.reload() +//! ``` + mod client; mod models; mod predictions; use std::env::var; use std::sync::OnceLock; + fn api_key() -> anyhow::Result<&'static str> { let api_key = var("REPLICATE_API_KEY")?; static REPLICATE_API_KEY: OnceLock = OnceLock::new();