Skip to content

Commit 26b2516

Browse files
author
David Motsonashvili
committed
update to match API doc
1 parent 4b77e46 commit 26b2516

File tree

14 files changed

+39
-55
lines changed

14 files changed

+39
-55
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import com.google.firebase.auth.internal.InternalAuthProvider
2424
import com.google.firebase.inject.Provider
2525
import com.google.firebase.vertexai.type.Content
2626
import com.google.firebase.vertexai.type.GenerationConfig
27-
import com.google.firebase.vertexai.type.ImageSafetySettings
27+
import com.google.firebase.vertexai.type.ImagenGenerationConfig
28+
import com.google.firebase.vertexai.type.ImagenSafetySettings
2829
import com.google.firebase.vertexai.type.ImagenModelConfig
2930
import com.google.firebase.vertexai.type.InvalidLocationException
3031
import com.google.firebase.vertexai.type.RequestOptions
@@ -84,8 +85,8 @@ internal constructor(
8485
@JvmOverloads
8586
public fun imageModel(
8687
modelName: String,
87-
generationConfig: ImagenModelConfig? = null,
88-
safetySettings: ImageSafetySettings? = null,
88+
generationConfig: ImagenGenerationConfig? = null,
89+
safetySettings: ImagenSafetySettings? = null,
8990
requestOptions: RequestOptions = RequestOptions(),
9091
): ImageModel {
9192
if (location.trim().isEmpty() || location.contains("/")) {

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import com.google.firebase.vertexai.internal.util.toInternal
1212
import com.google.firebase.vertexai.internal.util.toPublicGCS
1313
import com.google.firebase.vertexai.internal.util.toPublicInline
1414
import com.google.firebase.vertexai.type.FirebaseVertexAIException
15-
import com.google.firebase.vertexai.type.ImageSafetySettings
15+
import com.google.firebase.vertexai.type.ImagenSafetySettings
1616
import com.google.firebase.vertexai.type.ImagenGCSImage
1717
import com.google.firebase.vertexai.type.ImagenGenerationConfig
1818
import com.google.firebase.vertexai.type.ImagenGenerationResponse
19-
import com.google.firebase.vertexai.type.ImagenImageRepresentible
2019
import com.google.firebase.vertexai.type.ImagenInlineImage
2120
import com.google.firebase.vertexai.type.ImagenModelConfig
2221
import com.google.firebase.vertexai.type.PromptBlockedException
@@ -28,16 +27,16 @@ import kotlin.time.Duration.Companion.seconds
2827
public class ImageModel
2928
internal constructor(
3029
private val modelName: String,
31-
private val generationConfig: ImagenModelConfig? = null,
32-
private val safetySettings: ImageSafetySettings? = null,
30+
private val generationConfig: ImagenGenerationConfig? = null,
31+
private val safetySettings: ImagenSafetySettings? = null,
3332
private val controller: APIController,
3433
) {
3534
@JvmOverloads
3635
internal constructor(
3736
modelName: String,
3837
apiKey: String,
39-
generationConfig: ImagenModelConfig? = null,
40-
safetySettings: ImageSafetySettings? = null,
38+
generationConfig: ImagenGenerationConfig? = null,
39+
safetySettings: ImagenSafetySettings? = null,
4140
requestOptions: RequestOptions = RequestOptions(),
4241
appCheckTokenProvider: InteropAppCheckTokenProvider? = null,
4342
internalAuthProvider: InternalAuthProvider? = null,
@@ -90,21 +89,19 @@ internal constructor(
9089

9190
public suspend fun generateImage(
9291
prompt: String,
93-
config: ImagenGenerationConfig?,
9492
): ImagenGenerationResponse<ImagenInlineImage> =
9593
try {
96-
controller.generateImage(constructRequest(prompt, null, config)).toPublicInline().validate()
94+
controller.generateImage(constructRequest(prompt, null, generationConfig)).toPublicInline().validate()
9795
} catch (e: Throwable) {
9896
throw FirebaseVertexAIException.from(e)
9997
}
10098

10199
public suspend fun generateImage(
102100
prompt: String,
103101
gcsUri: String,
104-
config: ImagenGenerationConfig?,
105102
): ImagenGenerationResponse<ImagenGCSImage> =
106103
try {
107-
controller.generateImage(constructRequest(prompt, gcsUri, config)).toPublicGCS().validate()
104+
controller.generateImage(constructRequest(prompt, gcsUri, generationConfig)).toPublicGCS().validate()
108105
} catch (e: Throwable) {
109106
throw FirebaseVertexAIException.from(e)
110107
}
@@ -136,7 +133,7 @@ internal constructor(
136133
}
137134
}
138135

139-
private fun <T : ImagenImageRepresentible> ImagenGenerationResponse<T>.validate():
136+
private fun <T> ImagenGenerationResponse<T>.validate():
140137
ImagenGenerationResponse<T> {
141138
if (images.isEmpty()) {
142139
throw PromptBlockedException(message = filteredReason ?: ImageModel.DEFAULT_FILTERED_ERROR)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageResponse.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal data class GenerateImageResponse(val predictions: List<ImagenImageRespo
77

88
@Serializable
99
internal data class ImagenImageResponse(
10-
val bytesBase64Encoded: String?,
11-
val gcsUri: String?,
10+
val bytesBase64Encoded: String? = null,
11+
val gcsUri: String? = null,
1212
val mimeType: String,
1313
)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ internal fun com.google.firebase.vertexai.type.Schema.toInternal(): Schema =
205205
items?.toInternal(),
206206
)
207207

208-
internal fun com.google.firebase.vertexai.type.ImageFormat.toInternal(): ImageOutputOptions =
208+
internal fun com.google.firebase.vertexai.type.ImagenImageFormat.toInternal(): ImageOutputOptions =
209209
ImageOutputOptions(mimeType, compressionQuality)
210210

211211
internal fun JSONObject.toInternal() = Json.decodeFromString<JsonObject>(toString())

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.google.firebase.vertexai.type
22

3+
@Suppress("EnumEntryName")
34
public enum class ImagenAspectRatio(internal val internalVal: String) {
45
SQUARE_1x1("1:1"),
56
PORTRAIT_3x4("3:4"),
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
package com.google.firebase.vertexai.type
22

3-
public class ImagenGCSImage(public val gcsUri: String, public val mimeType: String) :
4-
ImagenImageRepresentible {
5-
6-
override fun asImagenImage(): ImagenImage {
7-
return ImagenImage(null, gcsUri, mimeType)
8-
}
9-
}
3+
public class ImagenGCSImage(public val gcsUri: String, public val mimeType: String) {}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.google.firebase.vertexai.type
22

33
public class ImagenGenerationConfig(
44
public val negativePrompt: String? = null,
5-
public val numberOfImages: Int = 1,
5+
public val numberOfImages: Int? = 1,
66
public val aspectRatio: ImagenAspectRatio? = null,
7+
public val imageFormat: ImagenImageFormat? = null,
8+
public val addWatermark: Boolean? = null
79
) {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.google.firebase.vertexai.type
22

3-
public class ImagenGenerationResponse<T : ImagenImageRepresentible>(
3+
public class ImagenGenerationResponse<T>(
44
public val images: List<T>,
55
public val filteredReason: String?,
66
) {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.google.firebase.vertexai.type
2+
3+
public class ImagenImageFormat
4+
private constructor(public val mimeType: String, public val compressionQuality: Int?) {
5+
6+
public companion object {
7+
public fun jpeg(compressionQuality: Int? = null): ImagenImageFormat {
8+
return ImagenImageFormat("image/jpeg", compressionQuality)
9+
}
10+
11+
public fun png(): ImagenImageFormat {
12+
return ImagenImageFormat("image/png", null)
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)