Skip to content

Commit

Permalink
feat(image): add quality and style fields (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam authored Jan 6, 2024
1 parent 548fb2d commit 049f733
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,25 @@ internal class ImagesApi(private val requester: HttpRequester) : Images {

/** Convert [ImageCreation] instance to base64 JSON request */
private fun ImageCreation.toJSONRequest() = ImageCreationRequest(
prompt = prompt, n = n, size = size, user = user, responseFormat = ImageResponseFormat.base64Json, model = model?.id,
prompt = prompt,
n = n,
size = size,
user = user,
responseFormat = ImageResponseFormat.base64Json,
model = model?.id,
quality = quality,
style = style,
)

/** Convert [ImageCreation] instance to URL request */
private fun ImageCreation.toURLRequest() = ImageCreationRequest(
prompt = prompt, n = n, size = size, user = user, responseFormat = ImageResponseFormat.url, model = model?.id
prompt = prompt,
n = n,
size = size,
user = user,
responseFormat = ImageResponseFormat.url,
model = model?.id,
quality = quality,
style = style,
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aallam.openai.api.image

import Quality
import com.aallam.openai.api.BetaOpenAI
import com.aallam.openai.api.OpenAIDsl
import com.aallam.openai.api.model.ModelId
Expand Down Expand Up @@ -30,6 +31,19 @@ public class ImageCreation(
* 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.
*/
public val model: ModelId? = null,

/**
* The quality of the image that will be generated. `Quality.HD` creates images with finer details and greater
* consistency across the image. This param is only supported for `dall-e-3`.
*/
public val quality: Quality? = null,

/**
* The style of the generated images. Must be one of [Style.Vivid] or `[Style.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. This param is only supported for dall-e-3.
*/
public val style: Style? = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline

/**
* The quality of the image that will be generated
*/
@Serializable
@JvmInline
public value class Quality(public val value: String) {
public companion object {
public val HD: Quality = Quality("hd")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.aallam.openai.api.image

import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline

/**
* The style of the generated images.
*/
@Serializable
@JvmInline
public value class Style(public val value: String) {
public companion object {
public val Vivid: Style = Style("vivid")
public val Natural: Style = Style("natural")
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.aallam.openai.api.image.internal

import Quality
import com.aallam.openai.api.BetaOpenAI
import com.aallam.openai.api.InternalOpenAI
import com.aallam.openai.api.image.ImageSize
import com.aallam.openai.api.image.Style
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Image generation request.
* Results are expected as URLs.
*/
@OptIn(BetaOpenAI::class)
@Serializable
@InternalOpenAI
public data class ImageCreationRequest(
Expand All @@ -20,4 +21,6 @@ public data class ImageCreationRequest(
@SerialName("user") val user: String? = null,
@SerialName("response_format") val responseFormat: ImageResponseFormat,
@SerialName("model") val model: String? = null,
@SerialName("quality") val quality: Quality? = null,
@SerialName("style") val style: Style? = null,
)

0 comments on commit 049f733

Please sign in to comment.