async_openai_alt/
image.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::{
5        CreateImageEditRequest, CreateImageRequest, CreateImageVariationRequest, ImagesResponse,
6    },
7    Client,
8};
9
10/// Given a prompt and/or an input image, the model will generate a new image.
11///
12/// Related guide: [Image generation](https://platform.openai.com/docs/guides/images)
13pub struct Images<'c, C: Config> {
14    client: &'c Client<C>,
15}
16
17impl<'c, C: Config> Images<'c, C> {
18    pub fn new(client: &'c Client<C>) -> Self {
19        Self { client }
20    }
21
22    /// Creates an image given a prompt.
23    pub async fn create(&self, request: CreateImageRequest) -> Result<ImagesResponse, OpenAIError> {
24        self.client.post("/images/generations", request).await
25    }
26
27    /// Creates an edited or extended image given an original image and a prompt.
28    pub async fn create_edit(
29        &self,
30        request: CreateImageEditRequest,
31    ) -> Result<ImagesResponse, OpenAIError> {
32        self.client.post_form("/images/edits", request).await
33    }
34
35    /// Creates a variation of a given image.
36    pub async fn create_variation(
37        &self,
38        request: CreateImageVariationRequest,
39    ) -> Result<ImagesResponse, OpenAIError> {
40        self.client.post_form("/images/variations", request).await
41    }
42}