// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Based on https://github.com/64bit/async-openai/ by Himanshu Neema // Original Copyright (c) 2022 Himanshu Neema // Licensed under MIT License (see ATTRIBUTIONS-Rust.md) // // Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. // Licensed under Apache 2.0 use crate::{ Client, config::Config, error::OpenAIError, types::{ CreateImageEditRequest, CreateImageRequest, CreateImageVariationRequest, ImagesResponse, }, }; /// Given a prompt and/or an input image, the model will generate a new image. /// /// Related guide: [Image generation](https://platform.openai.com/docs/guides/images) pub struct Images<'c, C: Config> { client: &'c Client, } impl<'c, C: Config> Images<'c, C> { pub fn new(client: &'c Client) -> Self { Self { client } } /// Creates an image given a prompt. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateImageRequest) -> Result { self.client.post("/images/generations", request).await } /// Creates an edited or extended image given an original image and a prompt. #[crate::byot( T0 = Clone, R = serde::de::DeserializeOwned, where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create_edit( &self, request: CreateImageEditRequest, ) -> Result { self.client.post_form("/images/edits", request).await } /// Creates a variation of a given image. #[crate::byot( T0 = Clone, R = serde::de::DeserializeOwned, where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create_variation( &self, request: CreateImageVariationRequest, ) -> Result { self.client.post_form("/images/variations", request).await } }