pub struct ImageGenerator { /* private fields */ }Expand description
Generates and edits images with an ImageProvider.
It is cheap to clone: clones share the provider and the storage.
let generator = ImageGenerator::new("openai::gpt-image-1")?.with_size("1024x1024");
let response = generator.generate("A lighthouse at dawn").await?;
println!("{} image", response.image.content_type);Implementations§
Source§impl ImageGenerator
impl ImageGenerator
Sourcepub fn new(model: &str) -> Result<Self, ImageError>
pub fn new(model: &str) -> Result<Self, ImageError>
Creates a generator for a model, see provider::from_model: the provider comes from
the name (openai::gpt-image-1) and its settings from environment variables.
Sourcepub fn from_provider(provider: impl ImageProvider) -> Self
pub fn from_provider(provider: impl ImageProvider) -> Self
Creates a generator with a provider you built, for example with the API key set in code.
Sourcepub fn with_storage(self, storage: impl MediaSave) -> Self
pub fn with_storage(self, storage: impl MediaSave) -> Self
Saves every image in storage and sets ImageResponse::id.
Sourcepub fn with_size(self, size: impl Into<String>) -> Self
pub fn with_size(self, size: impl Into<String>) -> Self
Size of every image that does not set its own, in the provider’s format (for example
1024x1024).
Sourcepub fn with_quality(self, quality: impl Into<String>) -> Self
pub fn with_quality(self, quality: impl Into<String>) -> Self
Quality of every image that does not set its own, in the provider’s format (for
example high).
Sourcepub fn supports_edit(&self) -> bool
pub fn supports_edit(&self) -> bool
Returns true when the provider can edit images.
Sourcepub async fn list_models(&self) -> Result<Vec<ImageModel>, ImageError>
pub async fn list_models(&self) -> Result<Vec<ImageModel>, ImageError>
Lists the image models of the provider, see provider::list_models.
Sourcepub async fn generate(
&self,
prompt: impl Into<String>,
) -> Result<ImageResponse, ImageError>
pub async fn generate( &self, prompt: impl Into<String>, ) -> Result<ImageResponse, ImageError>
Generates an image from a prompt.
Sourcepub async fn generate_with(
&self,
request: ImageRequest,
) -> Result<ImageResponse, ImageError>
pub async fn generate_with( &self, request: ImageRequest, ) -> Result<ImageResponse, ImageError>
Generates an image from a full request. Unset size and quality take the defaults.
Sourcepub async fn edit(
&self,
prompt: impl Into<String>,
images: Vec<Media>,
) -> Result<ImageResponse, ImageError>
pub async fn edit( &self, prompt: impl Into<String>, images: Vec<Media>, ) -> Result<ImageResponse, ImageError>
Edits images following a prompt.
Sourcepub async fn edit_with(
&self,
request: ImageEditRequest,
) -> Result<ImageResponse, ImageError>
pub async fn edit_with( &self, request: ImageEditRequest, ) -> Result<ImageResponse, ImageError>
Edits images with a full request. Unset size and quality take the defaults.