Skip to content

Commit 049f733

Browse files
authored
feat(image): add quality and style fields (#292)
1 parent 548fb2d commit 049f733

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/ImagesApi.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,25 @@ internal class ImagesApi(private val requester: HttpRequester) : Images {
9595

9696
/** Convert [ImageCreation] instance to base64 JSON request */
9797
private fun ImageCreation.toJSONRequest() = ImageCreationRequest(
98-
prompt = prompt, n = n, size = size, user = user, responseFormat = ImageResponseFormat.base64Json, model = model?.id,
98+
prompt = prompt,
99+
n = n,
100+
size = size,
101+
user = user,
102+
responseFormat = ImageResponseFormat.base64Json,
103+
model = model?.id,
104+
quality = quality,
105+
style = style,
99106
)
100107

101108
/** Convert [ImageCreation] instance to URL request */
102109
private fun ImageCreation.toURLRequest() = ImageCreationRequest(
103-
prompt = prompt, n = n, size = size, user = user, responseFormat = ImageResponseFormat.url, model = model?.id
110+
prompt = prompt,
111+
n = n,
112+
size = size,
113+
user = user,
114+
responseFormat = ImageResponseFormat.url,
115+
model = model?.id,
116+
quality = quality,
117+
style = style,
104118
)
105119
}

openai-core/src/commonMain/kotlin/com.aallam.openai.api/image/ImageCreation.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.aallam.openai.api.image
22

3+
import Quality
34
import com.aallam.openai.api.BetaOpenAI
45
import com.aallam.openai.api.OpenAIDsl
56
import com.aallam.openai.api.model.ModelId
@@ -30,6 +31,19 @@ public class ImageCreation(
3031
* The model used to generate image. Must be one of dall-e-2 or dall-e-3. If not provided, dall-e-2 is used.
3132
*/
3233
public val model: ModelId? = null,
34+
35+
/**
36+
* The quality of the image that will be generated. `Quality.HD` creates images with finer details and greater
37+
* consistency across the image. This param is only supported for `dall-e-3`.
38+
*/
39+
public val quality: Quality? = null,
40+
41+
/**
42+
* The style of the generated images. Must be one of [Style.Vivid] or `[Style.Natural]`. Vivid causes the model to
43+
* lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less
44+
* hyper-real looking images. This param is only supported for dall-e-3.
45+
*/
46+
public val style: Style? = null,
3347
)
3448

3549
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import kotlinx.serialization.Serializable
2+
import kotlin.jvm.JvmInline
3+
4+
/**
5+
* The quality of the image that will be generated
6+
*/
7+
@Serializable
8+
@JvmInline
9+
public value class Quality(public val value: String) {
10+
public companion object {
11+
public val HD: Quality = Quality("hd")
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.aallam.openai.api.image
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlin.jvm.JvmInline
5+
6+
/**
7+
* The style of the generated images.
8+
*/
9+
@Serializable
10+
@JvmInline
11+
public value class Style(public val value: String) {
12+
public companion object {
13+
public val Vivid: Style = Style("vivid")
14+
public val Natural: Style = Style("natural")
15+
}
16+
}

openai-core/src/commonMain/kotlin/com.aallam.openai.api/image/internal/ImageCreationRequest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.aallam.openai.api.image.internal
22

3+
import Quality
34
import com.aallam.openai.api.BetaOpenAI
45
import com.aallam.openai.api.InternalOpenAI
56
import com.aallam.openai.api.image.ImageSize
7+
import com.aallam.openai.api.image.Style
68
import kotlinx.serialization.SerialName
79
import kotlinx.serialization.Serializable
810

911
/**
1012
* Image generation request.
1113
* Results are expected as URLs.
1214
*/
13-
@OptIn(BetaOpenAI::class)
1415
@Serializable
1516
@InternalOpenAI
1617
public data class ImageCreationRequest(
@@ -20,4 +21,6 @@ public data class ImageCreationRequest(
2021
@SerialName("user") val user: String? = null,
2122
@SerialName("response_format") val responseFormat: ImageResponseFormat,
2223
@SerialName("model") val model: String? = null,
24+
@SerialName("quality") val quality: Quality? = null,
25+
@SerialName("style") val style: Style? = null,
2326
)

0 commit comments

Comments
 (0)