1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct CreateImageRequest {
/// A text description of the desired image(s). The maximum length is 32000 characters for the GPT image models, 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`.
#[serde(rename = "prompt")]
pub prompt: String,
#[serde(rename = "model", skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
#[serde(rename = "n", skip_serializing_if = "Option::is_none")]
pub n: Option<i32>,
/// The quality of the image that will be generated. - `auto` (default value) will automatically select the best quality for the given model. - `high`, `medium` and `low` are supported for the GPT image models. - `hd` and `standard` are supported for `dall-e-3`. - `standard` is the only option for `dall-e-2`.
#[serde(rename = "quality", skip_serializing_if = "Option::is_none")]
pub quality: Option<Quality>,
/// The format in which generated images with `dall-e-2` and `dall-e-3` are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This parameter isn't supported for the GPT image models, which always return base64-encoded images.
#[serde(rename = "response_format", skip_serializing_if = "Option::is_none")]
pub response_format: Option<ResponseFormat>,
/// The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
#[serde(rename = "output_format", skip_serializing_if = "Option::is_none")]
pub output_format: Option<OutputFormat>,
/// The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the `webp` or `jpeg` output formats, and defaults to 100.
#[serde(rename = "output_compression", skip_serializing_if = "Option::is_none")]
pub output_compression: Option<i32>,
/// Generate the image in streaming mode. Defaults to `false`. See the [Image generation guide](/docs/guides/image-generation) for more information. This parameter is only supported for the GPT image models.
#[serde(rename = "stream", skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
/// The number of partial images to generate. This parameter is used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event. Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly.
#[serde(
rename = "partial_images",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub partial_images: Option<Option<i32>>,
/// The size of the generated images. Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image models, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
#[serde(rename = "size", skip_serializing_if = "Option::is_none")]
pub size: Option<Size>,
/// Control the content-moderation level for images generated by the GPT image models. Must be either `low` for less restrictive filtering or `auto` (default value).
#[serde(rename = "moderation", skip_serializing_if = "Option::is_none")]
pub moderation: Option<Moderation>,
/// Allows to set transparency for the background of the generated image(s). This parameter is only supported for the GPT image models. Must be one of `transparent`, `opaque` or `auto` (default value). When `auto` is used, the model will automatically determine the best background for the image. If `transparent`, the output format needs to support transparency, so it should be set to either `png` (default value) or `webp`.
#[serde(rename = "background", skip_serializing_if = "Option::is_none")]
pub background: Option<Background>,
/// The style of the generated images. This parameter is only supported for `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.
#[serde(rename = "style", skip_serializing_if = "Option::is_none")]
pub style: Option<Style>,
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices#end-user-ids).
#[serde(rename = "user", skip_serializing_if = "Option::is_none")]
pub user: Option<String>,
}
impl CreateImageRequest {
pub fn new(prompt: String) -> CreateImageRequest {
CreateImageRequest {
prompt,
model: None,
n: None,
quality: None,
response_format: None,
output_format: None,
output_compression: None,
stream: None,
partial_images: None,
size: None,
moderation: None,
background: None,
style: None,
user: None,
}
}
}
/// The quality of the image that will be generated. - `auto` (default value) will automatically select the best quality for the given model. - `high`, `medium` and `low` are supported for the GPT image models. - `hd` and `standard` are supported for `dall-e-3`. - `standard` is the only option for `dall-e-2`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Quality {
#[serde(rename = "standard")]
Standard,
#[serde(rename = "hd")]
Hd,
#[serde(rename = "low")]
Low,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "high")]
High,
#[serde(rename = "auto")]
Auto,
}
impl Default for Quality {
fn default() -> Quality {
Self::Standard
}
}
/// The format in which generated images with `dall-e-2` and `dall-e-3` are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This parameter isn't supported for the GPT image models, which always return base64-encoded images.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ResponseFormat {
#[serde(rename = "url")]
Url,
#[serde(rename = "b64_json")]
B64Json,
}
impl Default for ResponseFormat {
fn default() -> ResponseFormat {
Self::Url
}
}
/// The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum OutputFormat {
#[serde(rename = "png")]
Png,
#[serde(rename = "jpeg")]
Jpeg,
#[serde(rename = "webp")]
Webp,
}
impl Default for OutputFormat {
fn default() -> OutputFormat {
Self::Png
}
}
/// The size of the generated images. Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image models, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Size {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "1024x1024")]
Variant1024x1024,
#[serde(rename = "1536x1024")]
Variant1536x1024,
#[serde(rename = "1024x1536")]
Variant1024x1536,
#[serde(rename = "256x256")]
Variant256x256,
#[serde(rename = "512x512")]
Variant512x512,
#[serde(rename = "1792x1024")]
Variant1792x1024,
#[serde(rename = "1024x1792")]
Variant1024x1792,
}
impl Default for Size {
fn default() -> Size {
Self::Auto
}
}
/// Control the content-moderation level for images generated by the GPT image models. Must be either `low` for less restrictive filtering or `auto` (default value).
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Moderation {
#[serde(rename = "low")]
Low,
#[serde(rename = "auto")]
Auto,
}
impl Default for Moderation {
fn default() -> Moderation {
Self::Low
}
}
/// Allows to set transparency for the background of the generated image(s). This parameter is only supported for the GPT image models. Must be one of `transparent`, `opaque` or `auto` (default value). When `auto` is used, the model will automatically determine the best background for the image. If `transparent`, the output format needs to support transparency, so it should be set to either `png` (default value) or `webp`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Background {
#[serde(rename = "transparent")]
Transparent,
#[serde(rename = "opaque")]
Opaque,
#[serde(rename = "auto")]
Auto,
}
impl Default for Background {
fn default() -> Background {
Self::Transparent
}
}
/// The style of the generated images. This parameter is only supported for `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Style {
#[serde(rename = "vivid")]
Vivid,
#[serde(rename = "natural")]
Natural,
}
impl Default for Style {
fn default() -> Style {
Self::Vivid
}
}
impl std::fmt::Display for CreateImageRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}