openai_rust2/
images.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Debug, Clone)]
4pub struct ImageArguments {
5    /// A text description of the desired image(s). The maximum length is 1000 characters.
6    pub prompt: String,
7    /// The model to use for image generation (e.g., "gpt-image-1").
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub model: Option<String>,
10    /// The number of images to generate. Must be between 1 and 10. Defaults to 1.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub n: Option<u32>,
13    /// The size of the generated images. Must be one of "1024x1024", "1024x1536", or "1536x1024". Defaults to "1024x1024".
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub size: Option<String>,
16    /// The quality of the generated images. Must be "standard" or "hd". Defaults to "standard".
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub quality: Option<String>,
19    /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub user: Option<String>,
22}
23
24impl ImageArguments {
25    pub fn new(prompt: impl AsRef<str>) -> Self {
26        Self {
27            prompt: prompt.as_ref().to_owned(),
28            model: None,
29            n: None,
30            size: None,
31            quality: None,
32            user: None,
33        }
34    }
35}
36
37#[derive(Deserialize, Debug)]
38pub(crate) enum ImageObject {
39    #[serde(alias = "url")]
40    Url(String),
41    #[serde(alias = "b64_json")]
42    Base64JSON(String),
43}
44
45#[derive(Deserialize, Debug)]
46pub(crate) struct ImageResponse {
47    #[allow(dead_code)]
48    created: u32,
49    pub data: Vec<ImageObject>,
50}