Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(image): add quality and style fields #292

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(image): add quality and style fields
  • Loading branch information
aallam committed Jan 6, 2024
commit 6edc6f4a6f372f7b7966ca77fb6c19e41bf06422
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,
)