1
1
/*
2
- * Copyright 2023-2024 the original author or authors.
2
+ * Copyright 2023-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
*
29
29
* @author Mark Pollack
30
30
* @author Christian Tzolov
31
+ * @author Jonghoon Park
31
32
* @since 0.8.0
32
33
*/
33
34
@ JsonInclude (JsonInclude .Include .NON_NULL )
@@ -46,6 +47,39 @@ public class OpenAiImageOptions implements ImageOptions {
46
47
@ JsonProperty ("model" )
47
48
private String model ;
48
49
50
+ /**
51
+ * Allows to set transparency for the background of the generated image(s). This
52
+ * parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
53
+ * `opaque` or `auto` (default value). When `auto` is used, the model will
54
+ * automatically determine the best background for the image. If `transparent`, the
55
+ * output format needs to support transparency, so it should be set to either `png`
56
+ * (default value) or `webp`.
57
+ */
58
+ @ JsonProperty ("background" )
59
+ private String background ;
60
+
61
+ /**
62
+ * Control the content-moderation level for images generated by `gpt-image-1`. Must be
63
+ * either `low` for less restrictive filtering or `auto` (default value).
64
+ */
65
+ @ JsonProperty ("moderation" )
66
+ private String moderation ;
67
+
68
+ /**
69
+ * The compression level (0-100%) for the generated images. This parameter is only
70
+ * supported for `gpt-image-1` with the `webp` or `jpeg` output formats, and defaults
71
+ * to 100.
72
+ */
73
+ @ JsonProperty ("output_compression" )
74
+ private Integer outputCompression ;
75
+
76
+ /**
77
+ * The format in which the generated images are returned. This parameter is only
78
+ * supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`.
79
+ */
80
+ @ JsonProperty ("output_format" )
81
+ private String outputFormat ;
82
+
49
83
/**
50
84
* The width of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
51
85
* This property is interconnected with the 'size' property - setting both width and
@@ -75,19 +109,22 @@ public class OpenAiImageOptions implements ImageOptions {
75
109
private String quality ;
76
110
77
111
/**
78
- * The format in which the generated images are returned. Must be one of url or
79
- * b64_json.
112
+ * The format in which generated images with `dall-e-2` and `dall-e-3` are returned.
113
+ * Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the
114
+ * image has been generated. This parameter isn't supported for `gpt-image-1` which
115
+ * will always return base64-encoded images.
80
116
*/
81
117
@ JsonProperty ("response_format" )
82
118
private String responseFormat ;
83
119
84
120
/**
85
- * The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for
86
- * dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.
87
- * This property is automatically computed when both width and height are set,
88
- * following the format "widthxheight". When setting this property directly, it must
89
- * follow the format "WxH" where W and H are valid integers. Invalid formats will
90
- * result in null width and height values.
121
+ * The size of the generated images. Must be one of `1024x1024`, `1536x1024`
122
+ * (landscape), `1024x1536` (portrait), or `auto` (default value) for `gpt-image-1`,
123
+ * one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of `1024x1024`,
124
+ * `1792x1024`, or `1024x1792` for `dall-e-3`. This property is automatically computed
125
+ * when both width and height are set, following the format "widthxheight". When
126
+ * setting this property directly, it must follow the format "WxH" where W and H are
127
+ * valid integers. Invalid formats will result in null width and height values.
91
128
*/
92
129
@ JsonProperty ("size" )
93
130
private String size ;
@@ -130,6 +167,38 @@ public void setModel(String model) {
130
167
this .model = model ;
131
168
}
132
169
170
+ public String getBackground () {
171
+ return background ;
172
+ }
173
+
174
+ public void setBackground (String background ) {
175
+ this .background = background ;
176
+ }
177
+
178
+ public String getModeration () {
179
+ return moderation ;
180
+ }
181
+
182
+ public void setModeration (String moderation ) {
183
+ this .moderation = moderation ;
184
+ }
185
+
186
+ public Integer getOutputCompression () {
187
+ return outputCompression ;
188
+ }
189
+
190
+ public void setOutputCompression (Integer outputCompression ) {
191
+ this .outputCompression = outputCompression ;
192
+ }
193
+
194
+ public String getOutputFormat () {
195
+ return outputFormat ;
196
+ }
197
+
198
+ public void setOutputFormat (String outputFormat ) {
199
+ this .outputFormat = outputFormat ;
200
+ }
201
+
133
202
public String getQuality () {
134
203
return this .quality ;
135
204
}
@@ -246,14 +315,17 @@ public boolean equals(Object o) {
246
315
247
316
@ Override
248
317
public int hashCode () {
249
- return Objects .hash (this .n , this .model , this .width , this .height , this .quality , this .responseFormat , this .size ,
250
- this .style , this .user );
318
+ return Objects .hash (this .n , this .model , this .background , this .moderation , this .outputCompression ,
319
+ this .outputFormat , this .width , this .height , this .quality , this .responseFormat , this .size , this .style ,
320
+ this .user );
251
321
}
252
322
253
323
@ Override
254
324
public String toString () {
255
- return "OpenAiImageOptions{" + "n=" + this .n + ", model='" + this .model + '\'' + ", width=" + this .width
256
- + ", height=" + this .height + ", quality='" + this .quality + '\'' + ", responseFormat='"
325
+ return "OpenAiImageOptions{" + "n=" + this .n + ", model='" + this .model + '\'' + ", background='"
326
+ + this .background + '\'' + ", moderation='" + this .moderation + '\'' + ", outputCompression='"
327
+ + this .outputCompression + '\'' + ", outputFormat='" + this .outputFormat + '\'' + ", width="
328
+ + this .width + ", height=" + this .height + ", quality='" + this .quality + '\'' + ", responseFormat='"
257
329
+ this .responseFormat + '\'' + ", size='" + this .size + '\'' + ", style='" + this .style + '\''
258
330
+ ", user='" + this .user + '\'' + '}' ;
259
331
}
@@ -276,6 +348,26 @@ public Builder model(String model) {
276
348
return this ;
277
349
}
278
350
351
+ public Builder background (String background ) {
352
+ this .options .setBackground (background );
353
+ return this ;
354
+ }
355
+
356
+ public Builder moderation (String moderation ) {
357
+ this .options .setModeration (moderation );
358
+ return this ;
359
+ }
360
+
361
+ public Builder outputCompression (Integer outputCompression ) {
362
+ this .options .setOutputCompression (outputCompression );
363
+ return this ;
364
+ }
365
+
366
+ public Builder outputFormat (String outputFormat ) {
367
+ this .options .setOutputFormat (outputFormat );
368
+ return this ;
369
+ }
370
+
279
371
public Builder quality (String quality ) {
280
372
this .options .setQuality (quality );
281
373
return this ;
@@ -306,41 +398,73 @@ public Builder user(String user) {
306
398
return this ;
307
399
}
308
400
401
+ /**
402
+ * @deprecated use {@link #N(Integer)} instead.
403
+ */
404
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
309
405
public Builder withN (Integer n ) {
310
406
this .options .setN (n );
311
407
return this ;
312
408
}
313
409
410
+ /**
411
+ * @deprecated use {@link #model(String)} instead.
412
+ */
413
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
314
414
public Builder withModel (String model ) {
315
415
this .options .setModel (model );
316
416
return this ;
317
417
}
318
418
419
+ /**
420
+ * @deprecated use {@link #quality(String)} instead.
421
+ */
422
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
319
423
public Builder withQuality (String quality ) {
320
424
this .options .setQuality (quality );
321
425
return this ;
322
426
}
323
427
428
+ /**
429
+ * @deprecated use {@link #responseFormat(String)} instead.
430
+ */
431
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
324
432
public Builder withResponseFormat (String responseFormat ) {
325
433
this .options .setResponseFormat (responseFormat );
326
434
return this ;
327
435
}
328
436
437
+ /**
438
+ * @deprecated use {@link #width(Integer)} instead.
439
+ */
440
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
329
441
public Builder withWidth (Integer width ) {
330
442
this .options .setWidth (width );
331
443
return this ;
332
444
}
333
445
446
+ /**
447
+ * @deprecated use {@link #height(Integer)} instead.
448
+ */
449
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
334
450
public Builder withHeight (Integer height ) {
335
451
this .options .setHeight (height );
336
452
return this ;
337
453
}
338
454
455
+ /**
456
+ * @deprecated use {@link #style(String)} instead.
457
+ */
458
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
339
459
public Builder withStyle (String style ) {
340
460
this .options .setStyle (style );
341
461
return this ;
342
462
}
343
463
464
+ /**
465
+ * @deprecated use {@link #user(String)} instead.
466
+ */
467
+ @ Deprecated (forRemoval = true , since = "1.0.0-M8" )
344
468
public Builder withUser (String user ) {
345
469
this .options .setUser (user );
346
470
return this ;
0 commit comments