Skip to main content

rig_core/client/
image_generation.rs

1#[cfg(feature = "image")]
2mod image {
3    use crate::image_generation::ImageGenerationModel;
4
5    /// A provider client with image generation capabilities.
6    /// Clone is required for conversions between client types.
7    pub trait ImageGenerationClient {
8        /// The ImageGenerationModel used by the Client
9        type ImageGenerationModel: ImageGenerationModel<Client = Self>;
10
11        /// Create an image generation model with the given name.
12        ///
13        /// # Example with OpenAI
14        /// ```no_run
15        /// use rig_core::prelude::*;
16        /// use rig_core::providers::openai::{Client, self};
17        ///
18        /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
19        /// // Initialize the OpenAI client
20        /// let openai = Client::new("your-open-ai-api-key")?;
21        ///
22        /// let gpt4 = openai.image_generation_model(openai::DALL_E_3);
23        /// # Ok(())
24        /// # }
25        /// ```
26        fn image_generation_model(&self, model: impl Into<String>) -> Self::ImageGenerationModel;
27
28        /// Create an image generation model with the given name.
29        ///
30        /// # Example with OpenAI
31        /// ```no_run
32        /// use rig_core::prelude::*;
33        /// use rig_core::providers::openai::{Client, self};
34        ///
35        /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
36        /// // Initialize the OpenAI client
37        /// let openai = Client::new("your-open-ai-api-key")?;
38        ///
39        /// let gpt4 = openai.image_generation_model(openai::DALL_E_3);
40        /// # Ok(())
41        /// # }
42        /// ```
43        fn custom_image_generation_model(
44            &self,
45            model: impl Into<String>,
46        ) -> Self::ImageGenerationModel {
47            Self::ImageGenerationModel::make(self, model)
48        }
49    }
50}
51
52#[cfg(feature = "image")]
53pub use image::*;