From 2c183968e454b7318d52decde59865d7750c83a3 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Mon, 6 Jan 2025 15:07:38 -0800 Subject: [PATCH 01/24] Add documentation to imagen --- .../firebase/vertexai/FirebaseVertexAI.kt | 9 +++++ .../google/firebase/vertexai/ImageModel.kt | 31 +++++++++++++++ .../vertexai/internal/GenerateImageRequest.kt | 16 ++++++++ .../internal/GenerateImageResponse.kt | 16 ++++++++ .../firebase/vertexai/type/ImageFormat.kt | 32 +++++++++++++++ .../vertexai/type/ImageSafetySettings.kt | 22 +++++++++++ .../vertexai/type/ImagenAspectRatio.kt | 39 +++++++++++++++++++ .../firebase/vertexai/type/ImagenGCSImage.kt | 22 +++++++++++ .../vertexai/type/ImagenGenerationConfig.kt | 23 +++++++++++ .../vertexai/type/ImagenGenerationResponse.kt | 23 +++++++++++ .../firebase/vertexai/type/ImagenImage.kt | 23 +++++++++++ .../vertexai/type/ImagenImageRepresentible.kt | 17 ++++++++ .../vertexai/type/ImagenInlineImage.kt | 25 ++++++++++++ .../vertexai/type/ImagenModelConfig.kt | 21 ++++++++++ .../vertexai/type/ImagenPersonFilter.kt | 30 ++++++++++++++ .../vertexai/type/ImagenSafetyFilter.kt | 31 +++++++++++++++ 16 files changed, 380 insertions(+) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt index 6d892048411..1ddb5a64d3e 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt @@ -81,6 +81,15 @@ internal constructor( ) } + /** + * Instantiates a new [ImageModel] given the provided parameters. + * + * @param modelName The name of the model to use, for example `"imagen-3.0-generate-001"`. + * @param generationConfig The configuration parameters to use for image generation. + * @param safetySettings The safety bounds the model will abide to during image generation. + * @param requestOptions Configuration options for sending requests to the backend. + * @return The initialized [ImageModel] instance. + */ @JvmOverloads public fun imageModel( modelName: String, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt index a66496e3748..d11424354f9 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai import android.util.Log @@ -25,6 +41,10 @@ import kotlinx.coroutines.tasks.await import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds +/** + * Represents an image model (like Imagen), capable of generating images based on various input + * types. + */ public class ImageModel internal constructor( private val modelName: String, @@ -88,6 +108,11 @@ internal constructor( ), ) + /** + * Generates an image, returning the result directly to the caller. + * @param prompt The main text prompt from which the image is generated. + * @param config contains secondary image generation parameters. + */ public suspend fun generateImage( prompt: String, config: ImagenGenerationConfig?, @@ -98,6 +123,12 @@ internal constructor( throw FirebaseVertexAIException.from(e) } + /** + * Generates an image, storing the result in Google Cloud Storage and returning a URL + * @param prompt The main text prompt from which the image is generated. + * @param gcsUri Specifies the GCS bucket in which to store the image. + * @param config contains secondary image generation parameters. + */ public suspend fun generateImage( prompt: String, gcsUri: String, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageRequest.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageRequest.kt index 95535be5b62..d826b11e87f 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageRequest.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageRequest.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.internal import com.google.firebase.vertexai.common.Request diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageResponse.kt index a46fc21172e..eab54f26a3e 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/GenerateImageResponse.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.internal import kotlinx.serialization.Serializable diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt index cd9fb87a3bd..adab0ddb49b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt @@ -1,13 +1,45 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type + +/** + * Represents the format an image should be returned in. + * @param mimeType A string (like "image/jpeg") specifying the encoding mimetype of the image. + * @param compressionQuality an int (1-100) representing how the quality of the image, a lower + * number meaning the image is permitted to be lower quality to reduce size. This parameter is not + * relevant for every mimetype + */ public class ImageFormat private constructor(public val mimeType: String, public val compressionQuality: Int?) { public companion object { + /** + * An [ImageFormat] representing a JPEG image. + * @param compressionQuality an int (1-100) representing how the quality of the image, a lower + * number meaning the image is permitted to be lower quality to reduce size. + */ public fun jpeg(compressionQuality: Int?): ImageFormat { return ImageFormat("image/jpeg", compressionQuality) } + /** + * An [ImageFormat] representing a PNG image + */ public fun png(): ImageFormat { return ImageFormat("image/png", null) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageSafetySettings.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageSafetySettings.kt index c43dcf0e99b..2304961ae6a 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageSafetySettings.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageSafetySettings.kt @@ -1,5 +1,27 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * A configuration for filtering unsafe content or images containing people. + * + * @param safetyFilterLevel Used to filter unsafe content. + * @param personFilterLevel Used to filter images containing people. + */ public class ImageSafetySettings internal constructor( internal val safetyFilterLevel: ImagenSafetyFilter, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt index 9435ac0c85f..6350a37df74 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt @@ -1,9 +1,48 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Represents the aspect ratio that the generated image should conform to. + */ +@Suppress("EnumEntryName") public enum class ImagenAspectRatio(internal val internalVal: String) { + /** + * A square image, useful for icons, profile pictures, etc. + */ SQUARE_1x1("1:1"), + + /** + * A portrait image in 3:4, the aspect ratio of older TVs. + */ PORTRAIT_3x4("3:4"), + + /** + * A landscape image in 4:3, the aspect ratio of older TVs. + */ LANDSCAPE_4x3("4:3"), + + /** + * A portrait image in 9:16, the aspect ratio of modern monitors and phone screens. + */ PORTRAIT_9x16("9:16"), + + /** + * A landscape image in 16:9, the aspect ratio of modern monitors and phone screens. + */ LANDSCAPE_16x9("16:9") } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt index 379b7bb81cc..e7513fb3ab6 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt @@ -1,5 +1,27 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Represents an Imagen Image that is contained in Google Cloud Storage. + * + * @param gcsUri Contains the gs:// uri for the image. + * @param mimeType Contains the mime type of the image eg. "image/png" + * */ public class ImagenGCSImage(public val gcsUri: String, public val mimeType: String) : ImagenImageRepresentible { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index 87c5ec8dedf..22ebb297c03 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -1,5 +1,28 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Contains extra settings to configure image generation + * @param negativePrompt This string contains things that should be explicitly be excluded from + * generated images. + * @param numberOfImages How many images should be generated. + * @param aspectRatio The aspect ratio of the generated images. + */ public class ImagenGenerationConfig( public val negativePrompt: String? = null, public val numberOfImages: Int = 1, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt index 3c278b61ab8..124bf948b06 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt @@ -1,5 +1,28 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Represents a response from Imagen call to [ImageModel#generateImages] + * + * @param images contains the generated images + * @param filteredReason if fewer images were generated than were requested, this field will contain + * the reason they were filtered out. + */ public class ImagenGenerationResponse( public val images: List, public val filteredReason: String?, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt index 4d92db3f92f..13e8789b0c3 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt @@ -1,5 +1,28 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Represents an abstract Imagen Image that is either contained inline or in Google Cloud Storage + * + * @param data Contains the raw bytes of the image, mutually exclusive with [gcsUri] + * @param gcsUri Contains the gs:// uri for the image , mutually exclusive with [data] + * @param mimeType Contains the mime type of the image eg. "image/png" + * */ public class ImagenImage( public val data: ByteArray?, public val gcsUri: String?, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt index de58264423a..e78096bd430 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt @@ -1,5 +1,22 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** Interface representing images which can be passed into Imagen (for upscaling, editing, etc.)*/ public interface ImagenImageRepresentible { public fun asImagenImage(): ImagenImage } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt index b7131d66884..b619b4c66da 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt @@ -1,9 +1,31 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type import android.graphics.Bitmap import android.graphics.BitmapFactory import android.util.Base64 +/** + * Represents an Imagen Image that is contained inline + * + * @param data Contains the raw bytes of the image + * @param mimeType Contains the mime type of the image eg. "image/png" + */ public class ImagenInlineImage(public val data: ByteArray, public val mimeType: String) : ImagenImageRepresentible { @@ -11,6 +33,9 @@ public class ImagenInlineImage(public val data: ByteArray, public val mimeType: return ImagenImage(data, null, mimeType) } + /** + * Returns the image as an android OS native [Bitmap] so that it can be saved or sent to the UI. + */ public fun asBitmap(): Bitmap { val data = Base64.decode(data, Base64.NO_WRAP) return BitmapFactory.decodeByteArray(data, 0, data.size) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt index f181297a819..8d9ee21ee3d 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt @@ -1,5 +1,26 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * Contains extra configuration options for the Imagen model. + * @param imageFormat Specifies the encoding format for the image. + * @param addWatermark If true, the image is invisibly watermarked as AI generated. + */ public class ImagenModelConfig private constructor( public val imageFormat: ImageFormat, public val addWatermark: Boolean? diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt index 84e6deed948..e5925225d3b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt @@ -1,7 +1,37 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type +/** + * A filter used to prevent images from containing depictions of people or children. + */ public enum class ImagenPersonFilter(internal val internalVal: String) { + /** + * Doesn't apply any filtering. + */ ALLOW_ALL("allow_all"), + + /** + * Filters out any images containing depictions of children. + */ ALLOW_ADULT("allow_adult"), + + /** + * Filters out any images with depictions of people. + */ BLOCK_ALL("dont_allow"), } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt index b24795e3063..93ef389a3c2 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt @@ -1,7 +1,38 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.type; +/** + * Used for safety filtering. + */ public enum class ImagenSafetyFilter(internal val internalVal: String) { + /** + * Strongest filtering level, most strict blocking. + */ BLOCK_LOW_AND_ABOVE("block_low_and_above"), + + /** + * Block some problematic prompts and responses. + */ BLOCK_MEDIUM_AND_ABOVE("block_medium_and_above"), + + /** + * Reduces the number of requests blocked due to safety filters. May increase objectionable + * content generated by Imagen. + */ BLOCK_ONLY_HIGH("block_only_high") } From 3bfde8277370f512e40b813a94d6fe560fbbbf35 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 7 Jan 2025 11:32:15 -0800 Subject: [PATCH 02/24] formatting --- .../google/firebase/vertexai/ImageModel.kt | 5 +-- .../firebase/vertexai/common/APIController.kt | 4 +-- .../firebase/vertexai/type/ImageFormat.kt | 5 +-- .../vertexai/type/ImagenAspectRatio.kt | 34 ++++++------------- .../firebase/vertexai/type/ImagenGCSImage.kt | 2 +- .../vertexai/type/ImagenGenerationConfig.kt | 6 ++-- .../firebase/vertexai/type/ImagenImage.kt | 2 +- .../vertexai/type/ImagenImageRepresentible.kt | 4 +-- .../vertexai/type/ImagenModelConfig.kt | 8 ++--- .../vertexai/type/ImagenPersonFilter.kt | 22 ++++-------- .../vertexai/type/ImagenSafetyFilter.kt | 28 ++++++--------- 11 files changed, 43 insertions(+), 77 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt index d11424354f9..5c6248bbfd1 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt @@ -37,9 +37,9 @@ import com.google.firebase.vertexai.type.ImagenInlineImage import com.google.firebase.vertexai.type.ImagenModelConfig import com.google.firebase.vertexai.type.PromptBlockedException import com.google.firebase.vertexai.type.RequestOptions -import kotlinx.coroutines.tasks.await import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds +import kotlinx.coroutines.tasks.await /** * Represents an image model (like Imagen), capable of generating images based on various input @@ -163,7 +163,8 @@ internal constructor( internal companion object { private val TAG = ImageModel::class.java.simpleName - internal const val DEFAULT_FILTERED_ERROR = "Unable to show generated images. All images were filtered out because they violated Vertex AI's usage guidelines. You will not be charged for blocked images. Try rephrasing the prompt. If you think this was an error, send feedback." + internal const val DEFAULT_FILTERED_ERROR = + "Unable to show generated images. All images were filtered out because they violated Vertex AI's usage guidelines. You will not be charged for blocked images. Try rephrasing the prompt. If you think this was an error, send feedback." } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt index cdbca35f0bf..0946d155e81 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt @@ -309,6 +309,4 @@ private fun GenerateContentResponse.validate() = apply { ?.let { throw ResponseStoppedException(this) } } -private fun GenerateImageResponse.validate() = apply { - -} +private fun GenerateImageResponse.validate() = apply {} diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt index adab0ddb49b..e3f90568182 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImageFormat.kt @@ -16,7 +16,6 @@ package com.google.firebase.vertexai.type - /** * Represents the format an image should be returned in. * @param mimeType A string (like "image/jpeg") specifying the encoding mimetype of the image. @@ -37,9 +36,7 @@ private constructor(public val mimeType: String, public val compressionQuality: return ImageFormat("image/jpeg", compressionQuality) } - /** - * An [ImageFormat] representing a PNG image - */ + /** An [ImageFormat] representing a PNG image */ public fun png(): ImageFormat { return ImageFormat("image/png", null) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt index 6350a37df74..d47a767e888 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenAspectRatio.kt @@ -16,33 +16,21 @@ package com.google.firebase.vertexai.type -/** - * Represents the aspect ratio that the generated image should conform to. - */ +/** Represents the aspect ratio that the generated image should conform to. */ @Suppress("EnumEntryName") public enum class ImagenAspectRatio(internal val internalVal: String) { - /** - * A square image, useful for icons, profile pictures, etc. - */ - SQUARE_1x1("1:1"), + /** A square image, useful for icons, profile pictures, etc. */ + SQUARE_1x1("1:1"), - /** - * A portrait image in 3:4, the aspect ratio of older TVs. - */ - PORTRAIT_3x4("3:4"), + /** A portrait image in 3:4, the aspect ratio of older TVs. */ + PORTRAIT_3x4("3:4"), - /** - * A landscape image in 4:3, the aspect ratio of older TVs. - */ - LANDSCAPE_4x3("4:3"), + /** A landscape image in 4:3, the aspect ratio of older TVs. */ + LANDSCAPE_4x3("4:3"), - /** - * A portrait image in 9:16, the aspect ratio of modern monitors and phone screens. - */ - PORTRAIT_9x16("9:16"), + /** A portrait image in 9:16, the aspect ratio of modern monitors and phone screens. */ + PORTRAIT_9x16("9:16"), - /** - * A landscape image in 16:9, the aspect ratio of modern monitors and phone screens. - */ - LANDSCAPE_16x9("16:9") + /** A landscape image in 16:9, the aspect ratio of modern monitors and phone screens. */ + LANDSCAPE_16x9("16:9") } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt index e7513fb3ab6..b8cdf0a94ec 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt @@ -21,7 +21,7 @@ package com.google.firebase.vertexai.type * * @param gcsUri Contains the gs:// uri for the image. * @param mimeType Contains the mime type of the image eg. "image/png" - * */ + */ public class ImagenGCSImage(public val gcsUri: String, public val mimeType: String) : ImagenImageRepresentible { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index 22ebb297c03..2c60ebed26d 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -24,7 +24,7 @@ package com.google.firebase.vertexai.type * @param aspectRatio The aspect ratio of the generated images. */ public class ImagenGenerationConfig( - public val negativePrompt: String? = null, - public val numberOfImages: Int = 1, - public val aspectRatio: ImagenAspectRatio? = null, + public val negativePrompt: String? = null, + public val numberOfImages: Int = 1, + public val aspectRatio: ImagenAspectRatio? = null, ) {} diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt index 13e8789b0c3..055e0cbe9cb 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt @@ -22,7 +22,7 @@ package com.google.firebase.vertexai.type * @param data Contains the raw bytes of the image, mutually exclusive with [gcsUri] * @param gcsUri Contains the gs:// uri for the image , mutually exclusive with [data] * @param mimeType Contains the mime type of the image eg. "image/png" - * */ + */ public class ImagenImage( public val data: ByteArray?, public val gcsUri: String?, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt index e78096bd430..04296a8bab9 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageRepresentible.kt @@ -16,7 +16,7 @@ package com.google.firebase.vertexai.type -/** Interface representing images which can be passed into Imagen (for upscaling, editing, etc.)*/ +/** Interface representing images which can be passed into Imagen (for upscaling, editing, etc.) */ public interface ImagenImageRepresentible { - public fun asImagenImage(): ImagenImage + public fun asImagenImage(): ImagenImage } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt index 8d9ee21ee3d..57ca11a88ba 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenModelConfig.kt @@ -21,9 +21,5 @@ package com.google.firebase.vertexai.type * @param imageFormat Specifies the encoding format for the image. * @param addWatermark If true, the image is invisibly watermarked as AI generated. */ -public class ImagenModelConfig private constructor( - public val imageFormat: ImageFormat, - public val addWatermark: Boolean? -) { - -} +public class ImagenModelConfig +private constructor(public val imageFormat: ImageFormat, public val addWatermark: Boolean?) {} diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt index e5925225d3b..fe2635ff8c0 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilter.kt @@ -16,22 +16,14 @@ package com.google.firebase.vertexai.type -/** - * A filter used to prevent images from containing depictions of people or children. - */ +/** A filter used to prevent images from containing depictions of people or children. */ public enum class ImagenPersonFilter(internal val internalVal: String) { - /** - * Doesn't apply any filtering. - */ - ALLOW_ALL("allow_all"), + /** Doesn't apply any filtering. */ + ALLOW_ALL("allow_all"), - /** - * Filters out any images containing depictions of children. - */ - ALLOW_ADULT("allow_adult"), + /** Filters out any images containing depictions of children. */ + ALLOW_ADULT("allow_adult"), - /** - * Filters out any images with depictions of people. - */ - BLOCK_ALL("dont_allow"), + /** Filters out any images with depictions of people. */ + BLOCK_ALL("dont_allow"), } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt index 93ef389a3c2..6090a0c1135 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilter.kt @@ -14,25 +14,19 @@ * limitations under the License. */ -package com.google.firebase.vertexai.type; +package com.google.firebase.vertexai.type -/** - * Used for safety filtering. - */ +/** Used for safety filtering. */ public enum class ImagenSafetyFilter(internal val internalVal: String) { - /** - * Strongest filtering level, most strict blocking. - */ - BLOCK_LOW_AND_ABOVE("block_low_and_above"), + /** Strongest filtering level, most strict blocking. */ + BLOCK_LOW_AND_ABOVE("block_low_and_above"), - /** - * Block some problematic prompts and responses. - */ - BLOCK_MEDIUM_AND_ABOVE("block_medium_and_above"), + /** Block some problematic prompts and responses. */ + BLOCK_MEDIUM_AND_ABOVE("block_medium_and_above"), - /** - * Reduces the number of requests blocked due to safety filters. May increase objectionable - * content generated by Imagen. - */ - BLOCK_ONLY_HIGH("block_only_high") + /** + * Reduces the number of requests blocked due to safety filters. May increase objectionable + * content generated by Imagen. + */ + BLOCK_ONLY_HIGH("block_only_high") } From 316e187a5cb49c81a3d7d7e59318409992cd6aeb Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 21 Jan 2025 12:21:18 -0800 Subject: [PATCH 03/24] format --- .../com/google/firebase/vertexai/ImageModel.kt | 15 ++++++++++----- .../vertexai/type/ImagenGenerationConfig.kt | 10 +++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt index 3febc04a2ce..c24623fc1ff 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImageModel.kt @@ -28,11 +28,11 @@ import com.google.firebase.vertexai.internal.util.toInternal import com.google.firebase.vertexai.internal.util.toPublicGCS import com.google.firebase.vertexai.internal.util.toPublicInline import com.google.firebase.vertexai.type.FirebaseVertexAIException -import com.google.firebase.vertexai.type.ImagenSafetySettings import com.google.firebase.vertexai.type.ImagenGCSImage import com.google.firebase.vertexai.type.ImagenGenerationConfig import com.google.firebase.vertexai.type.ImagenGenerationResponse import com.google.firebase.vertexai.type.ImagenInlineImage +import com.google.firebase.vertexai.type.ImagenSafetySettings import com.google.firebase.vertexai.type.PromptBlockedException import com.google.firebase.vertexai.type.RequestOptions import kotlin.time.Duration @@ -115,7 +115,10 @@ internal constructor( prompt: String, ): ImagenGenerationResponse = try { - controller.generateImage(constructRequest(prompt, null, generationConfig)).toPublicInline().validate() + controller + .generateImage(constructRequest(prompt, null, generationConfig)) + .toPublicInline() + .validate() } catch (e: Throwable) { throw FirebaseVertexAIException.from(e) } @@ -131,7 +134,10 @@ internal constructor( gcsUri: String, ): ImagenGenerationResponse = try { - controller.generateImage(constructRequest(prompt, gcsUri, generationConfig)).toPublicGCS().validate() + controller + .generateImage(constructRequest(prompt, gcsUri, generationConfig)) + .toPublicGCS() + .validate() } catch (e: Throwable) { throw FirebaseVertexAIException.from(e) } @@ -164,8 +170,7 @@ internal constructor( } } -private fun ImagenGenerationResponse.validate(): - ImagenGenerationResponse { +private fun ImagenGenerationResponse.validate(): ImagenGenerationResponse { if (images.isEmpty()) { throw PromptBlockedException(message = filteredReason ?: ImageModel.DEFAULT_FILTERED_ERROR) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index c07827ed1e7..acae920ab14 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -26,9 +26,9 @@ package com.google.firebase.vertexai.type * @param addWatermark Adds an invisible watermark to mark the image as AI generated. */ public class ImagenGenerationConfig( - public val negativePrompt: String? = null, - public val numberOfImages: Int? = 1, - public val aspectRatio: ImagenAspectRatio? = null, - public val imageFormat: ImagenImageFormat? = null, - public val addWatermark: Boolean? = null + public val negativePrompt: String? = null, + public val numberOfImages: Int? = 1, + public val aspectRatio: ImagenAspectRatio? = null, + public val imageFormat: ImagenImageFormat? = null, + public val addWatermark: Boolean? = null ) {} From fcd6bb67e23d107f586e8d07797839187633e93a Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 21 Jan 2025 12:22:30 -0800 Subject: [PATCH 04/24] minor doc fix in ImagenImageFormat --- .../com/google/firebase/vertexai/type/ImagenImageFormat.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt index ec4b36d2d18..d91ee78b5dc 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt @@ -36,7 +36,7 @@ private constructor(public val mimeType: String, public val compressionQuality: return ImagenImageFormat("image/jpeg", compressionQuality) } - /** An [ImagenFormat] representing a PNG image */ + /** An [ImagenImageFormat] representing a PNG image */ public fun png(): ImagenImageFormat { return ImagenImageFormat("image/png", null) } From 67e1dfe0dedec10e15901960f51e5f8039294c17 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 11:31:39 -0800 Subject: [PATCH 05/24] format --- .../google/firebase/vertexai/ImagenModel.kt | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt index 304378e1205..02e5af62635 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt @@ -34,12 +34,7 @@ import com.google.firebase.vertexai.type.ImagenGenerationConfig import com.google.firebase.vertexai.type.ImagenGenerationResponse import com.google.firebase.vertexai.type.ImagenInlineImage import com.google.firebase.vertexai.type.ImagenSafetySettings -import com.google.firebase.vertexai.type.ImagenSafetySettings -import com.google.firebase.vertexai.type.PromptBlockedException import com.google.firebase.vertexai.type.RequestOptions -import kotlin.time.Duration -import kotlin.time.Duration.Companion.seconds -import kotlinx.coroutines.tasks.await /** * Represents an image model (like Imagen), capable of generating images based on various input @@ -74,16 +69,14 @@ internal constructor( ), ) - /** - * Generates an image, returning the result directly to the caller. - * @param prompt The main text prompt from which the image is generated. - * @param config contains secondary image generation parameters. - */ + /** + * Generates an image, returning the result directly to the caller. + * @param prompt The main text prompt from which the image is generated. + * @param config contains secondary image generation parameters. + */ public suspend fun generateImages(prompt: String): ImagenGenerationResponse = try { - controller - .generateImage(constructRequest(prompt, null, generationConfig)) - .toPublicInline() + controller.generateImage(constructRequest(prompt, null, generationConfig)).toPublicInline() controller .generateImage(constructRequest(prompt, null, generationConfig)) .validate() @@ -92,12 +85,12 @@ internal constructor( throw FirebaseVertexAIException.from(e) } - /** - * Generates an image, storing the result in Google Cloud Storage and returning a URL - * @param prompt The main text prompt from which the image is generated. - * @param gcsUri Specifies the GCS bucket in which to store the image. - * @param config contains secondary image generation parameters. - */ + /** + * Generates an image, storing the result in Google Cloud Storage and returning a URL + * @param prompt The main text prompt from which the image is generated. + * @param gcsUri Specifies the GCS bucket in which to store the image. + * @param config contains secondary image generation parameters. + */ public suspend fun generateImages( prompt: String, gcsUri: String, From 4d4061518b202be9ac24c2e6d28256fd1735f111 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 11:39:55 -0800 Subject: [PATCH 06/24] format fixes --- .../com/google/firebase/vertexai/FirebaseVertexAI.kt | 4 ++-- .../kotlin/com/google/firebase/vertexai/ImagenModel.kt | 8 ++++---- .../firebase/vertexai/type/ImagenGenerationConfig.kt | 3 ++- .../google/firebase/vertexai/type/ImagenImageFormat.kt | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt index 77c1481924d..e4abb38bacb 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt @@ -82,13 +82,13 @@ internal constructor( } /** - * Instantiates a new [ImageModel] given the provided parameters. + * Instantiates a new [ImagenModel] given the provided parameters. * * @param modelName The name of the model to use, for example `"imagen-3.0-generate-001"`. * @param generationConfig The configuration parameters to use for image generation. * @param safetySettings The safety bounds the model will abide to during image generation. * @param requestOptions Configuration options for sending requests to the backend. - * @return The initialized [ImageModel] instance. + * @return The initialized [ImagenModel] instance. */ @JvmOverloads public fun imagenModel( diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt index 02e5af62635..6e5727c5473 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt @@ -71,8 +71,8 @@ internal constructor( /** * Generates an image, returning the result directly to the caller. - * @param prompt The main text prompt from which the image is generated. - * @param config contains secondary image generation parameters. + * + * @param prompt The input(s) given to the model as a prompt. */ public suspend fun generateImages(prompt: String): ImagenGenerationResponse = try { @@ -87,9 +87,9 @@ internal constructor( /** * Generates an image, storing the result in Google Cloud Storage and returning a URL - * @param prompt The main text prompt from which the image is generated. + * + * @param prompt The input(s) given to the model as a prompt. * @param gcsUri Specifies the GCS bucket in which to store the image. - * @param config contains secondary image generation parameters. */ public suspend fun generateImages( prompt: String, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index acae920ab14..2e94b61b312 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -17,7 +17,8 @@ package com.google.firebase.vertexai.type /** - * Contains extra settings to configure image generation + * Contains extra settings to configure image generation. + * * @param negativePrompt This string contains things that should be explicitly be excluded from * generated images. * @param numberOfImages How many images should be generated. diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt index d91ee78b5dc..dba26d2d3f6 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt @@ -29,6 +29,7 @@ private constructor(public val mimeType: String, public val compressionQuality: public companion object { /** * An [ImagenImageFormat] representing a JPEG image. + * * @param compressionQuality an int (1-100) representing how the quality of the image, a lower * number meaning the image is permitted to be lower quality to reduce size. */ From c3a31154db2a9da6c3147b6bf02307557611b6a5 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 13:41:59 -0800 Subject: [PATCH 07/24] add copyright to appcheckheaderprovider --- .../internal/util/AppCheckHeaderProvider.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/AppCheckHeaderProvider.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/AppCheckHeaderProvider.kt index 67140156070..2df31dcf660 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/AppCheckHeaderProvider.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/AppCheckHeaderProvider.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.firebase.vertexai.internal.util import android.util.Log From 42326fecab2699d8adc99ae90684b2529ec7df00 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:31:09 -0800 Subject: [PATCH 08/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt index e4abb38bacb..9e78e8811ba 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt @@ -86,7 +86,7 @@ internal constructor( * * @param modelName The name of the model to use, for example `"imagen-3.0-generate-001"`. * @param generationConfig The configuration parameters to use for image generation. - * @param safetySettings The safety bounds the model will abide to during image generation. + * @param safetySettings The safety bounds the model will abide by during image generation. * @param requestOptions Configuration options for sending requests to the backend. * @return The initialized [ImagenModel] instance. */ From 835045313479822c3d5c651491e5499d6ac1d6aa Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:31:15 -0800 Subject: [PATCH 09/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt index 6e5727c5473..307608ad695 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt @@ -37,7 +37,7 @@ import com.google.firebase.vertexai.type.ImagenSafetySettings import com.google.firebase.vertexai.type.RequestOptions /** - * Represents an image model (like Imagen), capable of generating images based on various input + * Represents a generative model (like Imagen), capable of generating images based on various input * types. */ public class ImagenModel From 800da6eafcd8ceae20016cc42dd17595c870e0ca Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:31:25 -0800 Subject: [PATCH 10/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt index 307608ad695..f165ef4952c 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt @@ -89,7 +89,7 @@ internal constructor( * Generates an image, storing the result in Google Cloud Storage and returning a URL * * @param prompt The input(s) given to the model as a prompt. - * @param gcsUri Specifies the GCS bucket in which to store the image. + * @param gcsUri Specifies the Google Cloud Storage bucket in which to store the image. */ public suspend fun generateImages( prompt: String, From ef1f5f3ca9ee7a6cbc67608778a409f7a53cb010 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:31:32 -0800 Subject: [PATCH 11/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../com/google/firebase/vertexai/type/ImagenGenerationConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index 2e94b61b312..44ffe6b11ad 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -19,7 +19,7 @@ package com.google.firebase.vertexai.type /** * Contains extra settings to configure image generation. * - * @param negativePrompt This string contains things that should be explicitly be excluded from + * @param negativePrompt This string contains things that should be explicitly excluded from * generated images. * @param numberOfImages How many images should be generated. * @param aspectRatio The aspect ratio of the generated images. From 7830a1b6d11345abdce8d69216d4b52acf6900dd Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:31:47 -0800 Subject: [PATCH 12/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../com/google/firebase/vertexai/type/ImagenInlineImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt index 56aa9891730..ae4917a7a0a 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt @@ -30,7 +30,7 @@ public class ImagenInlineImage internal constructor(public val data: ByteArray, public val mimeType: String) { /** - * Returns the image as an android OS native [Bitmap] so that it can be saved or sent to the UI. + * Returns the image as an Android OS native [Bitmap] so that it can be saved or sent to the UI. */ public fun asBitmap(): Bitmap { val data = Base64.decode(data, Base64.NO_WRAP) From 4416e1f5d5b966a2c55ea55e1e6adf573950c1a5 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:32:07 -0800 Subject: [PATCH 13/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../google/firebase/vertexai/type/ImagenPersonFilterLevel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt index c746db7ba36..2bd3f1584ae 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt @@ -24,7 +24,7 @@ public class ImagenPersonFilterLevel private constructor(internal val internalVa /** Filters out any images containing depictions of children. */ @JvmField public val ALLOW_ADULT: ImagenPersonFilterLevel = ImagenPersonFilterLevel("allow_adult") - /** Filters out any images with depictions of people. */ + /** Filters out any images containing depictions of people. */ @JvmField public val BLOCK_ALL: ImagenPersonFilterLevel = ImagenPersonFilterLevel("dont_allow") } } From 2e76e1e6c91588efa7de4087ece6892911400056 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:32:16 -0800 Subject: [PATCH 14/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt index f5e12e06c52..788fd0760b1 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenSafetyFilterLevel.kt @@ -29,7 +29,7 @@ public class ImagenSafetyFilterLevel private constructor(internal val internalVa ImagenSafetyFilterLevel("block_medium_and_above") /** * Reduces the number of requests blocked due to safety filters. May increase objectionable - * content generated by Imagen. + * content generated by the Imagen model. */ @JvmField public val BLOCK_ONLY_HIGH: ImagenSafetyFilterLevel = ImagenSafetyFilterLevel("block_only_high") From 9488bf8de5c3b5156c8f01e2cd84659fe8770c87 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:32:23 -0800 Subject: [PATCH 15/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../google/firebase/vertexai/type/ImagenPersonFilterLevel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt index 2bd3f1584ae..eabd51a4f94 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt @@ -16,7 +16,7 @@ package com.google.firebase.vertexai.type -/** A filter used to prevent images from containing depictions of people or children. */ +/** A filter used to prevent images from containing depictions of children or people. */ public class ImagenPersonFilterLevel private constructor(internal val internalVal: String) { public companion object { /** Doesn't apply any filtering. */ From 9312a81b5e6b5138785a329206c20e5bffb51e4e Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:32:48 -0800 Subject: [PATCH 16/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../kotlin/com/google/firebase/vertexai/type/ImagenImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt index ff4c184ba10..7fdad9eb066 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** - * Represents an abstract Imagen Image that is either contained inline or in Google Cloud Storage + * Represents an abstract Imagen Image that is either contained inline or in a Google Cloud Storage bucket * * @param data Contains the raw bytes of the image, mutually exclusive with [gcsUri] * @param gcsUri Contains the gs:// uri for the image , mutually exclusive with [data] From 0c917b57f895e629e9862af9f7422b22326aee65 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:34:54 -0800 Subject: [PATCH 17/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../kotlin/com/google/firebase/vertexai/type/ImagenImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt index 7fdad9eb066..2dcecb486ba 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImage.kt @@ -20,7 +20,7 @@ package com.google.firebase.vertexai.type * Represents an abstract Imagen Image that is either contained inline or in a Google Cloud Storage bucket * * @param data Contains the raw bytes of the image, mutually exclusive with [gcsUri] - * @param gcsUri Contains the gs:// uri for the image , mutually exclusive with [data] + * @param gcsUri Contains the `gs://` URI for the image, mutually exclusive with [data] * @param mimeType Contains the mime type of the image eg. "image/png" */ public class ImagenImage( From 2dcce15d807c6de3b39d41018265b9c5af54a37a Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 16:52:51 -0800 Subject: [PATCH 18/24] extra fixes for comments --- .../vertexai/type/ImagenGenerationResponse.kt | 2 +- .../firebase/vertexai/type/ImagenImageFormat.kt | 12 ++++++------ .../firebase/vertexai/type/ImagenInlineImage.kt | 2 +- .../vertexai/type/ImagenPersonFilterLevel.kt | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt index 68d5f226265..1873ce83258 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** - * Represents a response from Imagen call to [ImageModel#generateImages] + * Represents a response from a call to [ImagenModel#generateImages] * * @param images contains the generated images * @param filteredReason if fewer images were generated than were requested, this field will contain diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt index dba26d2d3f6..254ecd3e06e 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt @@ -18,10 +18,10 @@ package com.google.firebase.vertexai.type /** * Represents the format an image should be returned in. - * @param mimeType A string (like "image/jpeg") specifying the encoding mimetype of the image. - * @param compressionQuality an int (1-100) representing how the quality of the image, a lower - * number meaning the image is permitted to be lower quality to reduce size. This parameter is not - * relevant for every mimetype + * @param mimeType A string (like `"image/jpeg"`) specifying the encoding MIME type of the image. + * @param compressionQuality an int (1-100) representing the quality of the image; a lower + * number means the image is permitted to be lower quality to reduce size. This parameter is not + * relevant for every MIME type. */ public class ImagenImageFormat private constructor(public val mimeType: String, public val compressionQuality: Int?) { @@ -30,8 +30,8 @@ private constructor(public val mimeType: String, public val compressionQuality: /** * An [ImagenImageFormat] representing a JPEG image. * - * @param compressionQuality an int (1-100) representing how the quality of the image, a lower - * number meaning the image is permitted to be lower quality to reduce size. + * @param compressionQuality an int (1-100) representing the quality of the image; a lower + * number means the image is permitted to be lower quality to reduce size. */ public fun jpeg(compressionQuality: Int? = null): ImagenImageFormat { return ImagenImageFormat("image/jpeg", compressionQuality) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt index ae4917a7a0a..052d6d87298 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt @@ -24,7 +24,7 @@ import android.util.Base64 * Represents an Imagen Image that is contained inline * * @param data Contains the raw bytes of the image - * @param mimeType Contains the mime type of the image eg. "image/png" + * @param mimeType Contains the MIME type of the image (for example, `"image/png"`) */ public class ImagenInlineImage internal constructor(public val data: ByteArray, public val mimeType: String) { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt index eabd51a4f94..22d4bc13cc3 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenPersonFilterLevel.kt @@ -19,7 +19,7 @@ package com.google.firebase.vertexai.type /** A filter used to prevent images from containing depictions of children or people. */ public class ImagenPersonFilterLevel private constructor(internal val internalVal: String) { public companion object { - /** Doesn't apply any filtering. */ + /** No filters applied. */ @JvmField public val ALLOW_ALL: ImagenPersonFilterLevel = ImagenPersonFilterLevel("allow_all") /** Filters out any images containing depictions of children. */ @JvmField From 7859a7ff39c95b45462064386f64d950a1a3002e Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Tue, 28 Jan 2025 17:10:25 -0800 Subject: [PATCH 19/24] add documentation to ImagenGenerationConfig.Builder --- .../vertexai/type/ImagenGenerationConfig.kt | 33 +++++++++++++++++++ .../vertexai/type/ImagenImageFormat.kt | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index cbbc61a105b..41dee449e78 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -33,6 +33,19 @@ public class ImagenGenerationConfig( public val imageFormat: ImagenImageFormat? = null, public val addWatermark: Boolean? = null, ) { + /** + * Builder for creating a [ImagenGenerationConfig]. + * + * Mainly intended for Java interop. Kotlin consumers should use [imagenGenerationConfig] for a + * more idiomatic experience. + * + * @property negativePrompt See [ImagenGenerationConfig.negativePrompt]. + * @property numberOfImages See [ImagenGenerationConfig.numberOfImages]. + * @property aspectRatio See [ImagenGenerationConfig.aspectRatio]. + * @property imageFormat See [ImagenGenerationConfig.imageFormat] + * @property addWatermark See [ImagenGenerationConfig.addWatermark] + * @see [imagenGenerationConfig] + */ public class Builder { @JvmField public var negativePrompt: String? = null @JvmField public var numberOfImages: Int? = 1 @@ -40,6 +53,12 @@ public class ImagenGenerationConfig( @JvmField public var imageFormat: ImagenImageFormat? = null @JvmField public var addWatermark: Boolean? = null + /** + * Alternative casing for [ImagenGenerationConfig.Builder]: + * ``` + * val config = GenerationConfig.builder() + * ``` + */ public fun build(): ImagenGenerationConfig = ImagenGenerationConfig( negativePrompt = negativePrompt, @@ -55,6 +74,20 @@ public class ImagenGenerationConfig( } } +/** + * Helper method to construct a [ImagenGenerationConfig] in a DSL-like manner. + * + * Example Usage: + * ``` + * imagenGenerationConfig { + * negativePrompt = "People, black and white, painting" + * numberOfImages = 1 + * aspectRatio = ImagenAspecRatio.SQUARE_1x1 + * imageFormat = ImagenImageFormat.png() + * addWatermark = false + * } + * ``` + */ public fun imagenGenerationConfig( init: ImagenGenerationConfig.Builder.() -> Unit ): ImagenGenerationConfig { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt index 254ecd3e06e..feaec329374 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenImageFormat.kt @@ -19,9 +19,9 @@ package com.google.firebase.vertexai.type /** * Represents the format an image should be returned in. * @param mimeType A string (like `"image/jpeg"`) specifying the encoding MIME type of the image. - * @param compressionQuality an int (1-100) representing the quality of the image; a lower - * number means the image is permitted to be lower quality to reduce size. This parameter is not - * relevant for every MIME type. + * @param compressionQuality an int (1-100) representing the quality of the image; a lower number + * means the image is permitted to be lower quality to reduce size. This parameter is not relevant + * for every MIME type. */ public class ImagenImageFormat private constructor(public val mimeType: String, public val compressionQuality: Int?) { From 21d7082d8850177df252a4ed80f1ea61594b82f6 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Wed, 29 Jan 2025 10:08:30 -0800 Subject: [PATCH 20/24] update description of gcsURI --- .../main/kotlin/com/google/firebase/vertexai/ImagenModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt index f165ef4952c..7b68a2d8ef6 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt @@ -89,7 +89,8 @@ internal constructor( * Generates an image, storing the result in Google Cloud Storage and returning a URL * * @param prompt The input(s) given to the model as a prompt. - * @param gcsUri Specifies the Google Cloud Storage bucket in which to store the image. + * @param gcsUri Specifies where in Google Cloud Storage to store the image (for example, a + * specific bucket or folder). */ public suspend fun generateImages( prompt: String, From 0c82ffff20d5b153ce35d26cf04cebb2cce6ecfa Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Wed, 29 Jan 2025 11:44:00 -0800 Subject: [PATCH 21/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt index a2bea751ccc..4a9c1f7e632 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt @@ -19,7 +19,7 @@ package com.google.firebase.vertexai.type /** * Represents an Imagen Image that is contained in Google Cloud Storage. * - * @param gcsUri Contains the gs:// uri for the image. + * @param gcsUri Contains the `gs://` URI for the image. * @param mimeType Contains the mime type of the image eg. "image/png" */ public class ImagenGCSImage From fe6ca34312f44494ed9720ce7c5fc308f6e9b583 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Wed, 29 Jan 2025 11:44:14 -0800 Subject: [PATCH 22/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../com/google/firebase/vertexai/type/ImagenGenerationConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt index 41dee449e78..a90bb2c4288 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationConfig.kt @@ -36,7 +36,7 @@ public class ImagenGenerationConfig( /** * Builder for creating a [ImagenGenerationConfig]. * - * Mainly intended for Java interop. Kotlin consumers should use [imagenGenerationConfig] for a + * This is mainly intended for Java interop. For Kotlin, use [imagenGenerationConfig] for a * more idiomatic experience. * * @property negativePrompt See [ImagenGenerationConfig.negativePrompt]. From b7ef0e161af4bda1081fb1cb04eb9af59d33afc2 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Wed, 29 Jan 2025 11:44:35 -0800 Subject: [PATCH 23/24] Update firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt Co-authored-by: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> --- .../kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt index 4a9c1f7e632..a6decd05ab1 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt @@ -20,7 +20,7 @@ package com.google.firebase.vertexai.type * Represents an Imagen Image that is contained in Google Cloud Storage. * * @param gcsUri Contains the `gs://` URI for the image. - * @param mimeType Contains the mime type of the image eg. "image/png" + * @param mimeType Contains the MIME type of the image (for example, `"image/png"`). */ public class ImagenGCSImage internal constructor(public val gcsUri: String, public val mimeType: String) {} From 51af5530c3afeb5c985ed11f7d8fba572eae0119 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Wed, 29 Jan 2025 11:48:32 -0800 Subject: [PATCH 24/24] update description for Imagen-generated images --- .../kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt | 2 +- .../com/google/firebase/vertexai/type/ImagenInlineImage.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt index a6decd05ab1..765e27b3583 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGCSImage.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** - * Represents an Imagen Image that is contained in Google Cloud Storage. + * Represents an Imagen-generated image that is contained in Google Cloud Storage. * * @param gcsUri Contains the `gs://` URI for the image. * @param mimeType Contains the MIME type of the image (for example, `"image/png"`). diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt index 052d6d87298..5d83cea7d3b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt @@ -21,7 +21,7 @@ import android.graphics.BitmapFactory import android.util.Base64 /** - * Represents an Imagen Image that is contained inline + * Represents an Imagen-generated image that is contained inline * * @param data Contains the raw bytes of the image * @param mimeType Contains the MIME type of the image (for example, `"image/png"`)