diff --git a/ai-logic/firebase-ai/CHANGELOG.md b/ai-logic/firebase-ai/CHANGELOG.md index 43839080423..f3268acc5d0 100644 --- a/ai-logic/firebase-ai/CHANGELOG.md +++ b/ai-logic/firebase-ai/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- [changed] **Breaking Change**: Removed deprecated Imagen methods and types due to Imagen models being shut down in August 2026. As a replacement, you can [migrate your apps to use Gemini Image models (the "Nano Banana" models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration). + # 17.15.0 - [feature] Added support for `RealtimeInputConfig` and `ActivityDetectionConfig` to configure voice activity detection in Live API. Added `sendStartActivityRealtime` and `sendStopActivityRealtime` to `LiveSession` for manual activity control. (#8080) diff --git a/ai-logic/firebase-ai/api.txt b/ai-logic/firebase-ai/api.txt index 9b02089f183..3536d6f65a8 100644 --- a/ai-logic/firebase-ai/api.txt +++ b/ai-logic/firebase-ai/api.txt @@ -54,10 +54,6 @@ package com.google.firebase.ai { method public static com.google.firebase.ai.FirebaseAI getInstance(com.google.firebase.FirebaseApp app); method public static com.google.firebase.ai.FirebaseAI getInstance(com.google.firebase.FirebaseApp app = Firebase.app, com.google.firebase.ai.type.GenerativeBackend backend); method public static com.google.firebase.ai.FirebaseAI getInstance(com.google.firebase.FirebaseApp app = Firebase.app, com.google.firebase.ai.type.GenerativeBackend backend, boolean useLimitedUseAppCheckTokens); - method public com.google.firebase.ai.ImagenModel imagenModel(String modelName); - method public com.google.firebase.ai.ImagenModel imagenModel(String modelName, com.google.firebase.ai.type.ImagenGenerationConfig? generationConfig = null); - method public com.google.firebase.ai.ImagenModel imagenModel(String modelName, com.google.firebase.ai.type.ImagenGenerationConfig? generationConfig = null, com.google.firebase.ai.type.ImagenSafetySettings? safetySettings = null); - method public com.google.firebase.ai.ImagenModel imagenModel(String modelName, com.google.firebase.ai.type.ImagenGenerationConfig? generationConfig = null, com.google.firebase.ai.type.ImagenSafetySettings? safetySettings = null, com.google.firebase.ai.type.RequestOptions requestOptions = com.google.firebase.ai.type.RequestOptions()); method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.LiveGenerativeModel liveModel(String modelName); method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.LiveGenerativeModel liveModel(String modelName, com.google.firebase.ai.type.LiveGenerationConfig? generationConfig = null); method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.LiveGenerativeModel liveModel(String modelName, com.google.firebase.ai.type.LiveGenerationConfig? generationConfig = null, java.util.List? tools = null); @@ -67,8 +63,6 @@ package com.google.firebase.ai { method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateGenerativeModel templateGenerativeModel(com.google.firebase.ai.type.RequestOptions requestOptions = com.google.firebase.ai.type.RequestOptions()); method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateGenerativeModel templateGenerativeModel(com.google.firebase.ai.type.RequestOptions requestOptions = com.google.firebase.ai.type.RequestOptions(), java.util.List? tools = null); method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateGenerativeModel templateGenerativeModel(com.google.firebase.ai.type.RequestOptions requestOptions = com.google.firebase.ai.type.RequestOptions(), java.util.List? tools = null, com.google.firebase.ai.type.TemplateToolConfig? toolConfig = null); - method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateImagenModel templateImagenModel(); - method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateImagenModel templateImagenModel(com.google.firebase.ai.type.RequestOptions requestOptions = com.google.firebase.ai.type.RequestOptions()); property public static final com.google.firebase.ai.FirebaseAI instance; field public static final com.google.firebase.ai.FirebaseAI.Companion Companion; } @@ -110,13 +104,6 @@ package com.google.firebase.ai { property public final com.google.firebase.ai.OnDeviceExtension? onDeviceExtension; } - @Deprecated public final class ImagenModel { - method @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public suspend Object? editImage(java.util.List referenceImages, String prompt, com.google.firebase.ai.type.ImagenEditingConfig? config = null, kotlin.coroutines.Continuation>); - method @Deprecated public suspend Object? generateImages(String prompt, kotlin.coroutines.Continuation>); - method @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public suspend Object? inpaintImage(com.google.firebase.ai.type.ImagenInlineImage image, String prompt, com.google.firebase.ai.type.ImagenMaskReference mask, com.google.firebase.ai.type.ImagenEditingConfig config, kotlin.coroutines.Continuation>); - method @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public suspend Object? outpaintImage(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, String prompt = "", com.google.firebase.ai.type.ImagenEditingConfig? config = null, kotlin.coroutines.Continuation>); - } - @com.google.firebase.ai.type.PublicPreviewAPI public final class InferenceMode { field public static final com.google.firebase.ai.InferenceMode.Companion Companion; field public static final com.google.firebase.ai.InferenceMode ONLY_IN_CLOUD; @@ -214,10 +201,6 @@ package com.google.firebase.ai { method @com.google.firebase.ai.type.PublicPreviewAPI public com.google.firebase.ai.TemplateChat startChat(String templateId, java.util.Map inputs, java.util.List history = emptyList()); } - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class TemplateImagenModel { - method @Deprecated public suspend Object? generateImages(String templateId, java.util.Map inputs, kotlin.coroutines.Continuation>); - } - } package com.google.firebase.ai.annotations { @@ -273,21 +256,6 @@ package com.google.firebase.ai.java { method public com.google.firebase.ai.java.GenerativeModelFutures from(com.google.firebase.ai.GenerativeModel model); } - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenModelFutures { - method @Deprecated public abstract com.google.common.util.concurrent.ListenableFuture> editImage(java.util.List referenceImages, String prompt); - method @Deprecated public abstract com.google.common.util.concurrent.ListenableFuture> editImage(java.util.List referenceImages, String prompt, com.google.firebase.ai.type.ImagenEditingConfig? config = null); - method @Deprecated public static final com.google.firebase.ai.java.ImagenModelFutures from(com.google.firebase.ai.ImagenModel model); - method @Deprecated public abstract com.google.common.util.concurrent.ListenableFuture> generateImages(String prompt); - method @Deprecated public abstract com.google.firebase.ai.ImagenModel getImageModel(); - method @Deprecated public abstract com.google.common.util.concurrent.ListenableFuture> inpaintImage(com.google.firebase.ai.type.ImagenInlineImage image, String prompt, com.google.firebase.ai.type.ImagenMaskReference mask, com.google.firebase.ai.type.ImagenEditingConfig config); - method @Deprecated public abstract com.google.common.util.concurrent.ListenableFuture> outpaintImage(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, String prompt = "", com.google.firebase.ai.type.ImagenEditingConfig? config = null); - field @Deprecated public static final com.google.firebase.ai.java.ImagenModelFutures.Companion Companion; - } - - @Deprecated public static final class ImagenModelFutures.Companion { - method @Deprecated public com.google.firebase.ai.java.ImagenModelFutures from(com.google.firebase.ai.ImagenModel model); - } - @com.google.firebase.ai.type.PublicPreviewAPI public abstract class LiveModelFutures { method public abstract com.google.common.util.concurrent.ListenableFuture connect(); method public static final com.google.firebase.ai.java.LiveModelFutures from(com.google.firebase.ai.LiveGenerativeModel model); @@ -352,17 +320,6 @@ package com.google.firebase.ai.java { method public com.google.firebase.ai.java.TemplateGenerativeModelFutures from(com.google.firebase.ai.TemplateGenerativeModel model); } - public abstract class TemplateImagenModelFutures { - method public static final com.google.firebase.ai.java.TemplateImagenModelFutures from(com.google.firebase.ai.TemplateImagenModel model); - method public abstract com.google.common.util.concurrent.ListenableFuture> generateImages(String templateId, java.util.Map inputs); - method public abstract com.google.firebase.ai.TemplateImagenModel getImageModel(); - field public static final com.google.firebase.ai.java.TemplateImagenModelFutures.Companion Companion; - } - - public static final class TemplateImagenModelFutures.Companion { - method public com.google.firebase.ai.java.TemplateImagenModelFutures from(com.google.firebase.ai.TemplateImagenModel model); - } - } package com.google.firebase.ai.type { @@ -590,14 +547,6 @@ package com.google.firebase.ai.type { property public final int totalTokens; } - public final class Dimensions { - ctor public Dimensions(int width, int height); - method public int getHeight(); - method public int getWidth(); - property public final int height; - property public final int width; - } - public final class ExecutableCodePart implements com.google.firebase.ai.type.Part { ctor @Deprecated public ExecutableCodePart(String language, String code); method @com.google.firebase.ai.type.PublicPreviewAPI public static com.google.firebase.ai.type.ExecutableCodePart createWithThinking(String language, String code, boolean isThought, String? thoughtSignature); @@ -1027,224 +976,6 @@ package com.google.firebase.ai.type { public static final class ImageSize.Companion { } - @Deprecated public final class ImagenAspectRatio { - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio.Companion Companion; - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio LANDSCAPE_16x9; - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio LANDSCAPE_4x3; - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio PORTRAIT_3x4; - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio PORTRAIT_9x16; - field @Deprecated public static final com.google.firebase.ai.type.ImagenAspectRatio SQUARE_1x1; - } - - @Deprecated public static final class ImagenAspectRatio.Companion { - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenBackgroundMask extends com.google.firebase.ai.type.ImagenMaskReference { - ctor @Deprecated public ImagenBackgroundMask(Double? dilation = null); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenControlReference extends com.google.firebase.ai.type.ImagenReferenceImage { - ctor @Deprecated public ImagenControlReference(com.google.firebase.ai.type.ImagenControlType type, com.google.firebase.ai.type.ImagenInlineImage? image = null, Integer? referenceId = null, Boolean? enableComputation = null, Integer? superpixelRegionSize = null, Integer? superpixelRuler = null); - } - - @Deprecated public final class ImagenControlType { - field @Deprecated public static final com.google.firebase.ai.type.ImagenControlType CANNY; - field @Deprecated public static final com.google.firebase.ai.type.ImagenControlType COLOR_SUPERPIXEL; - field @Deprecated public static final com.google.firebase.ai.type.ImagenControlType.Companion Companion; - field @Deprecated public static final com.google.firebase.ai.type.ImagenControlType FACE_MESH; - field @Deprecated public static final com.google.firebase.ai.type.ImagenControlType SCRIBBLE; - } - - @Deprecated public static final class ImagenControlType.Companion { - } - - @Deprecated public final class ImagenEditMode { - field @Deprecated public static final com.google.firebase.ai.type.ImagenEditMode.Companion Companion; - field @Deprecated public static final com.google.firebase.ai.type.ImagenEditMode INPAINT_INSERTION; - field @Deprecated public static final com.google.firebase.ai.type.ImagenEditMode INPAINT_REMOVAL; - field @Deprecated public static final com.google.firebase.ai.type.ImagenEditMode OUTPAINT; - } - - @Deprecated public static final class ImagenEditMode.Companion { - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenEditingConfig { - ctor @Deprecated public ImagenEditingConfig(com.google.firebase.ai.type.ImagenEditMode? editMode = null, Integer? editSteps = null); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenForegroundMask extends com.google.firebase.ai.type.ImagenMaskReference { - ctor @Deprecated public ImagenForegroundMask(Double? dilation = null); - } - - @Deprecated public final class ImagenGenerationConfig { - ctor @Deprecated public ImagenGenerationConfig(String? negativePrompt = null, Integer? numberOfImages = 1, com.google.firebase.ai.type.ImagenAspectRatio? aspectRatio = null, com.google.firebase.ai.type.ImagenImageFormat? imageFormat = null, Boolean? addWatermark = null); - method @Deprecated public Boolean? getAddWatermark(); - method @Deprecated public com.google.firebase.ai.type.ImagenAspectRatio? getAspectRatio(); - method @Deprecated public com.google.firebase.ai.type.ImagenImageFormat? getImageFormat(); - method @Deprecated public String? getNegativePrompt(); - method @Deprecated public Integer? getNumberOfImages(); - property @Deprecated public final Boolean? addWatermark; - property @Deprecated public final com.google.firebase.ai.type.ImagenAspectRatio? aspectRatio; - property @Deprecated public final com.google.firebase.ai.type.ImagenImageFormat? imageFormat; - property @Deprecated public final String? negativePrompt; - property @Deprecated public final Integer? numberOfImages; - field @Deprecated public static final com.google.firebase.ai.type.ImagenGenerationConfig.Companion Companion; - } - - @Deprecated public static final class ImagenGenerationConfig.Builder { - ctor @Deprecated public ImagenGenerationConfig.Builder(); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig build(); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder setAddWatermark(boolean addWatermark); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder setAspectRatio(com.google.firebase.ai.type.ImagenAspectRatio aspectRatio); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder setImageFormat(com.google.firebase.ai.type.ImagenImageFormat imageFormat); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder setNegativePrompt(String negativePrompt); - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder setNumberOfImages(int numberOfImages); - field @Deprecated public Boolean? addWatermark; - field @Deprecated public com.google.firebase.ai.type.ImagenAspectRatio? aspectRatio; - field @Deprecated public com.google.firebase.ai.type.ImagenImageFormat? imageFormat; - field @Deprecated public String? negativePrompt; - field @Deprecated public Integer? numberOfImages; - } - - @Deprecated public static final class ImagenGenerationConfig.Companion { - method @Deprecated public com.google.firebase.ai.type.ImagenGenerationConfig.Builder builder(); - } - - public final class ImagenGenerationConfigKt { - method @Deprecated public static com.google.firebase.ai.type.ImagenGenerationConfig imagenGenerationConfig(kotlin.jvm.functions.Function1 init); - } - - @Deprecated public final class ImagenGenerationResponse { - method @Deprecated public String? getFilteredReason(); - method @Deprecated public java.util.List getImages(); - property @Deprecated public final String? filteredReason; - property @Deprecated public final java.util.List images; - } - - @Deprecated public final class ImagenImageFormat { - method @Deprecated public Integer? getCompressionQuality(); - method @Deprecated public String getMimeType(); - method @Deprecated public static com.google.firebase.ai.type.ImagenImageFormat jpeg(Integer? compressionQuality = null); - method @Deprecated public static com.google.firebase.ai.type.ImagenImageFormat png(); - property @Deprecated public final Integer? compressionQuality; - property @Deprecated public final String mimeType; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImageFormat.Companion Companion; - } - - @Deprecated public static final class ImagenImageFormat.Companion { - method @Deprecated public com.google.firebase.ai.type.ImagenImageFormat jpeg(Integer? compressionQuality = null); - method @Deprecated public com.google.firebase.ai.type.ImagenImageFormat png(); - } - - @Deprecated public final class ImagenImagePlacement { - method @Deprecated public static com.google.firebase.ai.type.ImagenImagePlacement fromCoordinate(int x, int y); - method @Deprecated public Integer? getX(); - method @Deprecated public Integer? getY(); - property @Deprecated public final Integer? x; - property @Deprecated public final Integer? y; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement BOTTOM_CENTER; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement BOTTOM_LEFT; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement BOTTOM_RIGHT; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement CENTER; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement.Companion Companion; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement LEFT_CENTER; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement RIGHT_CENTER; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement TOP_CENTER; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement TOP_LEFT; - field @Deprecated public static final com.google.firebase.ai.type.ImagenImagePlacement TOP_RIGHT; - } - - @Deprecated public static final class ImagenImagePlacement.Companion { - method @Deprecated public com.google.firebase.ai.type.ImagenImagePlacement fromCoordinate(int x, int y); - } - - @Deprecated public final class ImagenInlineImage { - method @Deprecated public android.graphics.Bitmap asBitmap(); - method @Deprecated public byte[] getData(); - method @Deprecated public String getMimeType(); - property @Deprecated public final byte[] data; - property @Deprecated public final String mimeType; - } - - public final class ImagenInlineImageKt { - method @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public static com.google.firebase.ai.type.ImagenInlineImage toImagenInlineImage(android.graphics.Bitmap); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenMaskReference extends com.google.firebase.ai.type.ImagenReferenceImage { - method @Deprecated public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method @Deprecated public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); - method @Deprecated public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); - field @Deprecated public static final com.google.firebase.ai.type.ImagenMaskReference.Companion Companion; - } - - @Deprecated public static final class ImagenMaskReference.Companion { - method @Deprecated public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method @Deprecated public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); - method @Deprecated public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); - } - - @Deprecated public final class ImagenPersonFilterLevel { - field @Deprecated public static final com.google.firebase.ai.type.ImagenPersonFilterLevel ALLOW_ADULT; - field @Deprecated public static final com.google.firebase.ai.type.ImagenPersonFilterLevel ALLOW_ALL; - field @Deprecated public static final com.google.firebase.ai.type.ImagenPersonFilterLevel BLOCK_ALL; - field @Deprecated public static final com.google.firebase.ai.type.ImagenPersonFilterLevel.Companion Companion; - } - - @Deprecated public static final class ImagenPersonFilterLevel.Companion { - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenRawImage extends com.google.firebase.ai.type.ImagenReferenceImage { - ctor @Deprecated public ImagenRawImage(com.google.firebase.ai.type.ImagenInlineImage image); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenRawMask extends com.google.firebase.ai.type.ImagenMaskReference { - ctor @Deprecated public ImagenRawMask(com.google.firebase.ai.type.ImagenInlineImage mask, Double? dilation = null); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenReferenceImage { - method @Deprecated public final com.google.firebase.ai.type.ImagenInlineImage? getImage(); - method @Deprecated public final Integer? getReferenceId(); - property @Deprecated public final com.google.firebase.ai.type.ImagenInlineImage? image; - property @Deprecated public final Integer? referenceId; - } - - @Deprecated public final class ImagenSafetyFilterLevel { - field @Deprecated public static final com.google.firebase.ai.type.ImagenSafetyFilterLevel BLOCK_LOW_AND_ABOVE; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSafetyFilterLevel BLOCK_MEDIUM_AND_ABOVE; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSafetyFilterLevel BLOCK_NONE; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSafetyFilterLevel BLOCK_ONLY_HIGH; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSafetyFilterLevel.Companion Companion; - } - - @Deprecated public static final class ImagenSafetyFilterLevel.Companion { - } - - @Deprecated public final class ImagenSafetySettings { - ctor @Deprecated public ImagenSafetySettings(com.google.firebase.ai.type.ImagenSafetyFilterLevel safetyFilterLevel, com.google.firebase.ai.type.ImagenPersonFilterLevel personFilterLevel); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenSemanticMask extends com.google.firebase.ai.type.ImagenMaskReference { - ctor @Deprecated public ImagenSemanticMask(java.util.List classes, Double? dilation = null); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenStyleReference extends com.google.firebase.ai.type.ImagenReferenceImage { - ctor @Deprecated public ImagenStyleReference(com.google.firebase.ai.type.ImagenInlineImage image, Integer? referenceId = null, String? description = null); - } - - @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenSubjectReference extends com.google.firebase.ai.type.ImagenReferenceImage { - ctor @Deprecated public ImagenSubjectReference(com.google.firebase.ai.type.ImagenInlineImage image, Integer? referenceId = null, String? description = null, com.google.firebase.ai.type.ImagenSubjectReferenceType? subjectType = null); - } - - @Deprecated public final class ImagenSubjectReferenceType { - field @Deprecated public static final com.google.firebase.ai.type.ImagenSubjectReferenceType ANIMAL; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSubjectReferenceType.Companion Companion; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSubjectReferenceType PERSON; - field @Deprecated public static final com.google.firebase.ai.type.ImagenSubjectReferenceType PRODUCT; - } - - @Deprecated public static final class ImagenSubjectReferenceType.Companion { - } - public final class InlineData { ctor public InlineData(byte[] data, String mimeType); ctor public InlineData(byte[] data, String mimeType, String? displayName); diff --git a/ai-logic/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ImagenTests.kt b/ai-logic/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ImagenTests.kt deleted file mode 100644 index fed138d602c..00000000000 --- a/ai-logic/firebase-ai/src/androidTest/kotlin/com/google/firebase/ai/ImagenTests.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.ai - -import com.google.firebase.ai.AIModels.Companion.app -import com.google.firebase.ai.type.ImagenBackgroundMask -import com.google.firebase.ai.type.ImagenEditMode -import com.google.firebase.ai.type.ImagenEditingConfig -import com.google.firebase.ai.type.ImagenRawImage -import com.google.firebase.ai.type.PublicPreviewAPI -import io.kotest.matchers.shouldBe -import kotlinx.coroutines.runBlocking -import org.junit.Ignore -import org.junit.Test - -@OptIn(PublicPreviewAPI::class) -class ImagenTests { - - @Ignore("Currently not supported by backend model") - @Test - fun testGenerateAndEditImage() { - val imageGenerationModel = FirebaseAI.getInstance(app()).imagenModel("imagen-3.0-generate-002") - val imageEditingModel = FirebaseAI.getInstance(app()).imagenModel("imagen-3.0-capability-001") - - runBlocking { - val catImage = imageGenerationModel.generateImages("A cat").images.first() - val editedCatImage = - imageEditingModel.editImage( - listOf(ImagenRawImage(catImage), ImagenBackgroundMask()), - "A cat flying through space", - ImagenEditingConfig(ImagenEditMode.INPAINT_INSERTION) - ) - editedCatImage.images.size shouldBe 1 - } - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAI.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAI.kt index 28267705175..22d67486306 100644 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAI.kt +++ b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAI.kt @@ -24,8 +24,6 @@ import com.google.firebase.ai.type.Content import com.google.firebase.ai.type.GenerationConfig import com.google.firebase.ai.type.GenerativeBackend import com.google.firebase.ai.type.GenerativeBackendEnum -import com.google.firebase.ai.type.ImagenGenerationConfig -import com.google.firebase.ai.type.ImagenSafetySettings import com.google.firebase.ai.type.LiveGenerationConfig import com.google.firebase.ai.type.PublicPreviewAPI import com.google.firebase.ai.type.RequestOptions @@ -235,76 +233,6 @@ internal constructor( ) } - /** - * Instantiates a new [ImagenModel] given the provided parameters. - * - * @param modelName The name of the model to use. See the documentation for a list of - * [supported models](https://firebase.google.com/docs/ai-logic/models). - * @param generationConfig The configuration parameters to use for 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. - */ - @JvmOverloads - public fun imagenModel( - modelName: String, - generationConfig: ImagenGenerationConfig? = null, - safetySettings: ImagenSafetySettings? = null, - requestOptions: RequestOptions = RequestOptions(), - ): ImagenModel { - val modelUri = - when (backend.backend) { - GenerativeBackendEnum.VERTEX_AI, - GenerativeBackendEnum.AGENT_PLATFORM -> - "projects/${firebaseApp.options.projectId}/locations/${backend.location}/publishers/google/models/${modelName}" - GenerativeBackendEnum.GOOGLE_AI -> - "projects/${firebaseApp.options.projectId}/models/${modelName}" - } - if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) { - Log.w( - TAG, - """Unsupported Imagen model "${modelName}"; see - https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names. - """ - .trimIndent(), - ) - } - return ImagenModel( - modelUri, - firebaseApp.options.apiKey, - firebaseApp, - useLimitedUseAppCheckTokens, - generationConfig, - safetySettings, - requestOptions, - appCheckProvider.get(), - internalAuthProvider.get(), - ) - } - - /** - * Instantiates a new [TemplateImagenModel] given the provided parameters. - * - * @param requestOptions Configuration options for sending requests to the backend. - * @return The initialized [TemplateImagenModel] instance. - */ - @JvmOverloads - @PublicPreviewAPI - public fun templateImagenModel( - requestOptions: RequestOptions = RequestOptions(), - ): TemplateImagenModel { - val templateUri = getTemplateUri(backend) - return TemplateImagenModel( - templateUri, - firebaseApp.options.apiKey, - firebaseApp, - useLimitedUseAppCheckTokens, - requestOptions, - appCheckProvider.get(), - internalAuthProvider.get(), - ) - } - public companion object { /** The [FirebaseAI] instance for the default [FirebaseApp] using the Google AI Backend. */ @JvmStatic @@ -354,8 +282,6 @@ internal constructor( private const val GEMINI_MODEL_NAME_PREFIX = "gemini-" - private const val IMAGEN_MODEL_NAME_PREFIX = "imagen-" - private val TAG = FirebaseAI::class.java.simpleName } diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt deleted file mode 100644 index d5ab2802e70..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt +++ /dev/null @@ -1,269 +0,0 @@ -/* - * 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.ai - -import com.google.firebase.FirebaseApp -import com.google.firebase.ai.common.APIController -import com.google.firebase.ai.common.AppCheckHeaderProvider -import com.google.firebase.ai.common.GenerateImageRequest -import com.google.firebase.ai.type.ContentBlockedException -import com.google.firebase.ai.type.Dimensions -import com.google.firebase.ai.type.FirebaseAIException -import com.google.firebase.ai.type.ImagenEditMode -import com.google.firebase.ai.type.ImagenEditingConfig -import com.google.firebase.ai.type.ImagenGenerationConfig -import com.google.firebase.ai.type.ImagenGenerationResponse -import com.google.firebase.ai.type.ImagenImagePlacement -import com.google.firebase.ai.type.ImagenInlineImage -import com.google.firebase.ai.type.ImagenMaskReference -import com.google.firebase.ai.type.ImagenRawImage -import com.google.firebase.ai.type.ImagenReferenceImage -import com.google.firebase.ai.type.ImagenSafetySettings -import com.google.firebase.ai.type.PublicPreviewAPI -import com.google.firebase.ai.type.RequestOptions -import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider -import com.google.firebase.auth.internal.InternalAuthProvider - -/** - * Represents a generative model (like Imagen), capable of generating images based on various input - * types. - * - * See the documentation for a list of - * [supported models](https://firebase.google.com/docs/ai-logic/models). - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenModel -internal constructor( - private val modelName: String, - private val generationConfig: ImagenGenerationConfig? = null, - private val safetySettings: ImagenSafetySettings? = null, - private val controller: APIController, -) { - @JvmOverloads - internal constructor( - modelName: String, - apiKey: String, - firebaseApp: FirebaseApp, - useLimitedUseAppCheckTokens: Boolean, - generationConfig: ImagenGenerationConfig? = null, - safetySettings: ImagenSafetySettings? = null, - requestOptions: RequestOptions = RequestOptions(), - appCheckTokenProvider: InteropAppCheckTokenProvider? = null, - internalAuthProvider: InternalAuthProvider? = null, - ) : this( - modelName, - generationConfig, - safetySettings, - APIController( - apiKey, - modelName, - requestOptions, - "gl-kotlin/${KotlinVersion.CURRENT}-ai fire/${BuildConfig.VERSION_NAME}", - firebaseApp, - AppCheckHeaderProvider( - TAG, - useLimitedUseAppCheckTokens, - appCheckTokenProvider, - internalAuthProvider - ), - ), - ) - - /** - * Generates an image, returning the result directly to the caller. - * - * @param prompt The input(s) given to the model as a prompt. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public suspend fun generateImages(prompt: String): ImagenGenerationResponse = - try { - controller - .generateImage(constructGenerateImageRequest(prompt, generationConfig)) - .validate() - .toPublicInline() - } catch (e: Throwable) { - throw FirebaseAIException.from(e) - } - - /** - * Generates an image from a single or set of base images, returning the result directly to the - * caller. - * - * @param referenceImages the image inputs given to the model as a prompt - * @param prompt the text input given to the model as a prompt - * @param config the editing configuration settings - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @PublicPreviewAPI - public suspend fun editImage( - referenceImages: List, - prompt: String, - config: ImagenEditingConfig? = null, - ): ImagenGenerationResponse = - try { - controller - .generateImage(constructEditRequest(referenceImages, prompt, config)) - .validate() - .toPublicInline() - } catch (e: Throwable) { - throw FirebaseAIException.from(e) - } - - /** - * Generates an image by inpainting a masked off part of a base image. Inpainting is the process - * of filling in missing or masked off parts of the image using context from the original image - * and prompt. - * - * @param image the base image - * @param prompt the text input given to the model as a prompt - * @param mask the mask which defines where in the image can be painted by Imagen. - * @param config the editing configuration settings, it should include an [ImagenEditMode] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @PublicPreviewAPI - public suspend fun inpaintImage( - image: ImagenInlineImage, - prompt: String, - mask: ImagenMaskReference, - config: ImagenEditingConfig, - ): ImagenGenerationResponse { - return editImage(listOf(ImagenRawImage(image), mask), prompt, config) - } - - /** - * Generates an image by outpainting the given image, extending its content beyond the original - * borders using context from the original image, and optionally, the prompt. - * - * @param image the base image - * @param newDimensions the new dimensions for the image, *must* be larger than the original - * image. - * @param newPosition the placement of the base image within the new image. This can either be - * coordinates (0,0 is the top left corner) or an alignment (ex: - * [ImagenImagePlacement.BOTTOM_CENTER]) - * @param prompt optional, can be used to specify the background generated if context is - * insufficient - * @param config the editing configuration settings - * @see [ImagenMaskReference.generateMaskAndPadForOutpainting] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @PublicPreviewAPI - public suspend fun outpaintImage( - image: ImagenInlineImage, - newDimensions: Dimensions, - newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, - prompt: String = "", - config: ImagenEditingConfig? = null, - ): ImagenGenerationResponse { - return editImage( - ImagenMaskReference.generateMaskAndPadForOutpainting(image, newDimensions, newPosition), - prompt, - ImagenEditingConfig(ImagenEditMode.OUTPAINT, config?.editSteps) - ) - } - - private fun constructGenerateImageRequest( - prompt: String, - generationConfig: ImagenGenerationConfig? = null, - ): GenerateImageRequest { - @OptIn(PublicPreviewAPI::class) - return GenerateImageRequest( - listOf(GenerateImageRequest.ImagenPrompt(prompt, null)), - GenerateImageRequest.ImagenParameters( - sampleCount = generationConfig?.numberOfImages ?: 1, - includeRaiReason = true, - includeSafetyAttributes = true, - addWatermark = generationConfig?.addWatermark, - personGeneration = safetySettings?.personFilterLevel?.internalVal, - negativePrompt = generationConfig?.negativePrompt, - safetySetting = safetySettings?.safetyFilterLevel?.internalVal, - storageUri = null, - aspectRatio = generationConfig?.aspectRatio?.internalVal, - imageOutputOptions = generationConfig?.imageFormat?.toInternal(), - editMode = null, - editConfig = null, - ), - ) - } - - @PublicPreviewAPI - private fun constructEditRequest( - referenceImages: List, - prompt: String, - editConfig: ImagenEditingConfig?, - ): GenerateImageRequest { - var maxRefId = referenceImages.mapNotNull { it.referenceId }.maxOrNull() ?: 1 - return GenerateImageRequest( - listOf( - GenerateImageRequest.ImagenPrompt( - prompt = prompt, - referenceImages = referenceImages.map { it.toInternal(++maxRefId) }, - ) - ), - GenerateImageRequest.ImagenParameters( - sampleCount = generationConfig?.numberOfImages ?: 1, - includeRaiReason = true, - includeSafetyAttributes = true, - addWatermark = generationConfig?.addWatermark, - personGeneration = safetySettings?.personFilterLevel?.internalVal, - negativePrompt = generationConfig?.negativePrompt, - safetySetting = safetySettings?.safetyFilterLevel?.internalVal, - storageUri = null, - aspectRatio = generationConfig?.aspectRatio?.internalVal, - imageOutputOptions = generationConfig?.imageFormat?.toInternal(), - editMode = editConfig?.editMode?.value, - editConfig = editConfig?.toInternal(), - ), - ) - } - - internal companion object { - private val TAG = ImagenModel::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." - } -} - -@OptIn(PublicPreviewAPI::class) -internal fun ImagenGenerationResponse.Internal.validate(): ImagenGenerationResponse.Internal { - if (predictions.none { it.mimeType != null }) { - throw ContentBlockedException( - message = predictions.first { it.raiFilteredReason != null }.raiFilteredReason - ?: ImagenModel.DEFAULT_FILTERED_ERROR - ) - } - return this -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/TemplateImagenModel.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/TemplateImagenModel.kt deleted file mode 100644 index 5c855a030f1..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/TemplateImagenModel.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.ai - -import com.google.firebase.FirebaseApp -import com.google.firebase.ai.common.APIController -import com.google.firebase.ai.common.AppCheckHeaderProvider -import com.google.firebase.ai.common.JSON -import com.google.firebase.ai.common.TemplateGenerateImageRequest -import com.google.firebase.ai.type.FirebaseAIException -import com.google.firebase.ai.type.ImagenGenerationResponse -import com.google.firebase.ai.type.ImagenInlineImage -import com.google.firebase.ai.type.PublicPreviewAPI -import com.google.firebase.ai.type.RequestOptions -import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider -import com.google.firebase.auth.internal.InternalAuthProvider -import kotlinx.serialization.json.jsonObject -import org.json.JSONObject - -/** - * Represents a generative model (like Imagen), capable of generating images based a template. - * - * See the documentation for a list of - * [supported models](https://firebase.google.com/docs/ai-logic/models). - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class TemplateImagenModel -internal constructor( - private val templateUri: String, - private val controller: APIController, -) { - - @JvmOverloads - internal constructor( - templateUri: String, - apiKey: String, - firebaseApp: FirebaseApp, - useLimitedUseAppCheckTokens: Boolean, - requestOptions: RequestOptions = RequestOptions(), - appCheckTokenProvider: InteropAppCheckTokenProvider? = null, - internalAuthProvider: InternalAuthProvider? = null, - ) : this( - templateUri, - APIController( - apiKey, - "", - requestOptions, - "gl-kotlin/${KotlinVersion.CURRENT}-ai fire/${BuildConfig.VERSION_NAME}", - firebaseApp, - AppCheckHeaderProvider( - TAG, - useLimitedUseAppCheckTokens, - appCheckTokenProvider, - internalAuthProvider - ), - ), - ) - - /** - * Generates an image, returning the result directly to the caller. - * - * @param templateId The ID of server prompt template. - * @param inputs the inputs needed to fill in the prompt - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public suspend fun generateImages( - templateId: String, - inputs: Map - ): ImagenGenerationResponse = - try { - controller - .templateGenerateImage( - "$templateUri$templateId", - constructTemplateGenerateImageRequest(inputs) - ) - .validate() - .toPublicInline() - } catch (e: Throwable) { - throw FirebaseAIException.from(e) - } - - private fun constructTemplateGenerateImageRequest( - inputs: Map - ): TemplateGenerateImageRequest { - return TemplateGenerateImageRequest( - JSON.parseToJsonElement(JSONObject(inputs).toString()).jsonObject - ) - } - - internal companion object { - private val TAG = TemplateImagenModel::class.java.simpleName - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt index f4bdcbb7bbc..8bbd8d67d2b 100644 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt +++ b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt @@ -33,7 +33,6 @@ import com.google.firebase.ai.type.GRpcErrorResponse import com.google.firebase.ai.type.GenerateContentResponse import com.google.firebase.ai.type.GenerativeBackend import com.google.firebase.ai.type.GenerativeBackendEnum -import com.google.firebase.ai.type.ImagenGenerationResponse import com.google.firebase.ai.type.InvalidAPIKeyException import com.google.firebase.ai.type.PromptBlockedException import com.google.firebase.ai.type.PublicPreviewAPI @@ -215,37 +214,6 @@ internal constructor( .map { it.validate() } .catch { throw FirebaseAIException.from(it) } - suspend fun generateImage(request: GenerateImageRequest): ImagenGenerationResponse.Internal = - try { - client - .post("${requestOptions.endpoint}/${requestOptions.apiVersion}/$model:predict") { - applyCommonConfiguration(request) - applyHeaderProvider() - } - .also { validateResponse(it) } - .body() - } catch (e: Throwable) { - throw FirebaseAIException.from(e) - } - - suspend fun templateGenerateImage( - templateId: String, - request: TemplateGenerateImageRequest - ): ImagenGenerationResponse.Internal = - try { - client - .post( - "${requestOptions.endpoint}/${requestOptions.apiVersion}/$templateId:templatePredict" - ) { - applyCommonConfiguration(request) - applyHeaderProvider() - } - .also { validateResponse(it) } - .body() - } catch (e: Throwable) { - throw FirebaseAIException.from(e) - } - private fun getBidiEndpoint(location: String): String = when (backend?.backend) { GenerativeBackendEnum.VERTEX_AI, @@ -310,9 +278,7 @@ internal constructor( when (request) { is GenerateContentRequest -> setBody(request) is CountTokensRequest -> setBody(request) - is GenerateImageRequest -> setBody(request) is TemplateGenerateContentRequest -> setBody(request) - is TemplateGenerateImageRequest -> setBody(request) } applyCommonHeaders() } diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt index e1442689d04..3c73a683133 100644 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt +++ b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt @@ -21,16 +21,11 @@ import com.google.firebase.ai.common.util.fullModelName import com.google.firebase.ai.common.util.trimmedModelName import com.google.firebase.ai.type.Content import com.google.firebase.ai.type.GenerationConfig -import com.google.firebase.ai.type.ImagenEditingConfig -import com.google.firebase.ai.type.ImagenImageFormat -import com.google.firebase.ai.type.ImagenReferenceImage -import com.google.firebase.ai.type.PublicPreviewAPI import com.google.firebase.ai.type.SafetySetting import com.google.firebase.ai.type.TemplateTool import com.google.firebase.ai.type.Tool import com.google.firebase.ai.type.ToolConfig import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject @@ -55,8 +50,6 @@ internal data class TemplateGenerateContentRequest( val toolConfig: ToolConfig.Internal? = null, ) : Request -@Serializable internal data class TemplateGenerateImageRequest(val inputs: JsonObject) : Request - @Serializable internal data class CountTokensRequest( val generateContentRequest: GenerateContentRequest? = null, @@ -87,44 +80,3 @@ internal data class CountTokensRequest( ) } } - -@Serializable -@OptIn(PublicPreviewAPI::class) -internal data class GenerateImageRequest( - val instances: List, - val parameters: ImagenParameters, -) : Request { - @Serializable - internal data class ImagenPrompt( - val prompt: String?, - val referenceImages: List? - ) - - @Serializable - internal data class ImagenParameters( - val sampleCount: Int, - val includeRaiReason: Boolean, - val includeSafetyAttributes: Boolean, - val storageUri: String?, - val negativePrompt: String?, - val aspectRatio: String?, - val safetySetting: String?, - val personGeneration: String?, - val addWatermark: Boolean?, - val imageOutputOptions: ImagenImageFormat.Internal?, - val editMode: String?, - @OptIn(PublicPreviewAPI::class) val editConfig: ImagenEditingConfig.Internal?, - ) - - @Serializable - internal enum class ReferenceType { - @SerialName("REFERENCE_TYPE_UNSPECIFIED") UNSPECIFIED, - @SerialName("REFERENCE_TYPE_RAW") RAW, - @SerialName("REFERENCE_TYPE_MASK") MASK, - @SerialName("REFERENCE_TYPE_CONTROL") CONTROL, - @SerialName("REFERENCE_TYPE_STYLE") STYLE, - @SerialName("REFERENCE_TYPE_SUBJECT") SUBJECT, - @SerialName("REFERENCE_TYPE_MASKED_SUBJECT") MASKED_SUBJECT, - @SerialName("REFERENCE_TYPE_PRODUCT") PRODUCT - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/ImagenModelFutures.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/ImagenModelFutures.kt deleted file mode 100644 index 1914f71d4a5..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/ImagenModelFutures.kt +++ /dev/null @@ -1,205 +0,0 @@ -/* - * 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.ai.java - -import androidx.concurrent.futures.SuspendToFutureAdapter -import com.google.common.util.concurrent.ListenableFuture -import com.google.firebase.ai.ImagenModel -import com.google.firebase.ai.type.Dimensions -import com.google.firebase.ai.type.ImagenEditMode -import com.google.firebase.ai.type.ImagenEditingConfig -import com.google.firebase.ai.type.ImagenGenerationResponse -import com.google.firebase.ai.type.ImagenImagePlacement -import com.google.firebase.ai.type.ImagenInlineImage -import com.google.firebase.ai.type.ImagenMaskReference -import com.google.firebase.ai.type.ImagenReferenceImage -import com.google.firebase.ai.type.PublicPreviewAPI - -/** - * Wrapper class providing Java compatible methods for [ImagenModel]. - * - * @see [ImagenModel] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public abstract class ImagenModelFutures internal constructor() { - /** - * Generates an image, returning the result directly to the caller. - * - * @param prompt The main text prompt from which the image is generated. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun generateImages( - prompt: String, - ): ListenableFuture> - - /** - * Generates an image from a single or set of base images, returning the result directly to the - * caller. - * - * @param prompt the text input given to the model as a prompt - * @param referenceImages the image inputs given to the model as a prompt - * @param config the editing configuration settings - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun editImage( - referenceImages: List, - prompt: String, - config: ImagenEditingConfig? = null - ): ListenableFuture> - - /** - * Generates an image from a single or set of base images, returning the result directly to the - * caller. - * - * @param prompt the text input given to the model as a prompt - * @param referenceImages the image inputs given to the model as a prompt - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun editImage( - referenceImages: List, - prompt: String, - ): ListenableFuture> - - /** - * Generates an image by inpainting a masked off part of a base image. - * - * @param image the base image - * @param prompt the text input given to the model as a prompt - * @param mask the mask which defines where in the image can be painted by imagen. - * @param config the editing configuration settings, it should include an [ImagenEditMode] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun inpaintImage( - image: ImagenInlineImage, - prompt: String, - mask: ImagenMaskReference, - config: ImagenEditingConfig, - ): ListenableFuture> - - /** - * Generates an image by outpainting the image, extending its borders - * - * @param image the base image - * @param newDimensions the new dimensions for the image, *must* be larger than the original - * image. - * @param newPosition the placement of the base image within the new image. This can either be - * coordinates (0,0 is the top left corner) or an alignment (ex: - * [ImagenImagePlacement.BOTTOM_CENTER]) - * @param prompt optional, but can be used to specify the background generated if context is - * insufficient - * @param config the editing configuration settings - * @see [ImagenMaskReference.generateMaskAndPadForOutpainting] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun outpaintImage( - image: ImagenInlineImage, - newDimensions: Dimensions, - newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, - prompt: String = "", - config: ImagenEditingConfig? = null, - ): ListenableFuture> - - /** - * Returns the [ImagenModel] object wrapped by this object. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public abstract fun getImageModel(): ImagenModel - - private class FuturesImpl(private val model: ImagenModel) : ImagenModelFutures() { - override fun generateImages( - prompt: String, - ): ListenableFuture> = - SuspendToFutureAdapter.launchFuture { model.generateImages(prompt) } - - override fun editImage( - referenceImages: List, - prompt: String, - config: ImagenEditingConfig? - ): ListenableFuture> = - SuspendToFutureAdapter.launchFuture { model.editImage(referenceImages, prompt, config) } - - override fun editImage( - referenceImages: List, - prompt: String, - ): ListenableFuture> = - editImage(referenceImages, prompt, null) - - override fun inpaintImage( - image: ImagenInlineImage, - prompt: String, - mask: ImagenMaskReference, - config: ImagenEditingConfig - ): ListenableFuture> = - SuspendToFutureAdapter.launchFuture { model.inpaintImage(image, prompt, mask, config) } - - override fun outpaintImage( - image: ImagenInlineImage, - newDimensions: Dimensions, - newPosition: ImagenImagePlacement, - prompt: String, - config: ImagenEditingConfig? - ): ListenableFuture> = - SuspendToFutureAdapter.launchFuture { - model.outpaintImage(image, newDimensions, newPosition, prompt, config) - } - - override fun getImageModel(): ImagenModel = model - } - - public companion object { - - /** - * @return a [ImagenModelFutures] created around the provided [ImagenModel] - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmStatic - public fun from(model: ImagenModel): ImagenModelFutures = FuturesImpl(model) - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/TemplateImagenModelFutures.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/TemplateImagenModelFutures.kt deleted file mode 100644 index 5a38982fbda..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/java/TemplateImagenModelFutures.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.ai.java - -import androidx.concurrent.futures.SuspendToFutureAdapter -import com.google.common.util.concurrent.ListenableFuture -import com.google.firebase.ai.TemplateImagenModel -import com.google.firebase.ai.type.ImagenGenerationResponse -import com.google.firebase.ai.type.ImagenInlineImage -import com.google.firebase.ai.type.PublicPreviewAPI - -/** - * Wrapper class providing Java compatible methods for [TemplateImagenModel]. - * - * @see [TemplateImagenModel] - */ -@OptIn(PublicPreviewAPI::class) -public abstract class TemplateImagenModelFutures internal constructor() { - - /** - * Generates an image, returning the result directly to the caller. - * - * @param templateId The ID of server prompt template. - * @param inputs the inputs needed to fill in the prompt - */ - public abstract fun generateImages( - templateId: String, - inputs: Map - ): ListenableFuture> - - /** Returns the [TemplateImagenModel] object wrapped by this object. */ - public abstract fun getImageModel(): TemplateImagenModel - - private class FuturesImpl(private val model: TemplateImagenModel) : TemplateImagenModelFutures() { - override fun generateImages( - templateId: String, - inputs: Map - ): ListenableFuture> { - return SuspendToFutureAdapter.launchFuture { model.generateImages(templateId, inputs) } - } - - override fun getImageModel(): TemplateImagenModel { - return model - } - } - public companion object { - - /** @return a [TemplateImagenModelFutures] created around the provided [TemplateImagenModel] */ - @JvmStatic - public fun from(model: TemplateImagenModel): TemplateImagenModelFutures = FuturesImpl(model) - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Dimensions.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Dimensions.kt deleted file mode 100644 index 98f256f39b2..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Dimensions.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents the dimensions of an image in pixels - * @param width the width of the image in pixels - * @param height the height of the image in pixels - */ -public class Dimensions(public val width: Int, public val height: Int) {} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenAspectRatio.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenAspectRatio.kt deleted file mode 100644 index 450c31bbad3..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenAspectRatio.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents the aspect ratio that the generated image should conform to. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenAspectRatio private constructor(internal val internalVal: String) { - public companion object { - /** A square image, useful for icons, profile pictures, etc. */ - @JvmField public val SQUARE_1x1: ImagenAspectRatio = ImagenAspectRatio("1:1") - /** A portrait image in 3:4, the aspect ratio of older TVs. */ - @JvmField public val PORTRAIT_3x4: ImagenAspectRatio = ImagenAspectRatio("3:4") - /** A landscape image in 4:3, the aspect ratio of older TVs. */ - @JvmField public val LANDSCAPE_4x3: ImagenAspectRatio = ImagenAspectRatio("4:3") - /** A portrait image in 9:16, the aspect ratio of modern monitors and phone screens. */ - @JvmField public val PORTRAIT_9x16: ImagenAspectRatio = ImagenAspectRatio("9:16") - /** A landscape image in 16:9, the aspect ratio of modern monitors and phone screens. */ - @JvmField public val LANDSCAPE_16x9: ImagenAspectRatio = ImagenAspectRatio("16:9") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlConfig.kt deleted file mode 100644 index c6f3b01af6c..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlConfig.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -internal class ImagenControlConfig( - internal val controlType: ImagenControlType, - internal val enableComputation: Boolean? = null, - internal val superpixelRegionSize: Int? = null, - internal val superpixelRuler: Int? = null -) { - - fun toInternal(): Internal { - return Internal( - controlType = controlType.value, - enableControlImageComputation = enableComputation, - superpixelRegionSize = superpixelRegionSize, - superpixelRuler = superpixelRuler - ) - } - - @Serializable - internal class Internal( - val controlType: String?, - val enableControlImageComputation: Boolean?, - val superpixelRegionSize: Int?, - val superpixelRuler: Int? - ) -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlType.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlType.kt deleted file mode 100644 index 1c565c2a80b..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlType.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents a control type for controlled Imagen generation/editing - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenControlType internal constructor(internal val value: String) { - public companion object { - - /** - * Use edge detection to ensure the new image follows the same outlines as the reference image. - */ - @JvmField public val CANNY: ImagenControlType = ImagenControlType("CONTROL_TYPE_CANNY") - - /** - * Use enhanced edge detection to ensure the new image follows the same outlines as the - * reference image. - */ - @JvmField public val SCRIBBLE: ImagenControlType = ImagenControlType("CONTROL_TYPE_SCRIBBLE") - - /** - * Use face mesh control to ensure that the new image has the same facial expressions as the - * reference image. - */ - @JvmField public val FACE_MESH: ImagenControlType = ImagenControlType("CONTROL_TYPE_FACE_MESH") - - /** - * Use color superpixels to ensure that the new image is similar in shape and color to the - * reference image. - */ - @JvmField - public val COLOR_SUPERPIXEL: ImagenControlType = - ImagenControlType("CONTROL_TYPE_COLOR_SUPERPIXEL") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt deleted file mode 100644 index 2b5265c7025..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents the edit mode for Imagen - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenEditMode private constructor(internal val value: String) { - - public companion object { - /** Inserts a new element into an image */ - @JvmField - public val INPAINT_INSERTION: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_INSERTION") - /** Removes an element from an image */ - @JvmField - public val INPAINT_REMOVAL: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_REMOVAL") - /** Extends the borders of an image outwards */ - @JvmField public val OUTPAINT: ImagenEditMode = ImagenEditMode("EDIT_MODE_OUTPAINT") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt deleted file mode 100644 index f9a67bc4d60..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditingConfig.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -/** - * Contains the editing settings which are not specific to a reference image - * @param editMode holds the editing mode if the request is for inpainting or outpainting - * @param editSteps the number of intermediate steps to include in the editing process - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenEditingConfig( - internal val editMode: ImagenEditMode? = null, - internal val editSteps: Int? = null, -) { - internal fun toInternal(): Internal { - return Internal(baseSteps = editSteps) - } - - @Serializable - internal data class Internal( - val baseSteps: Int?, - ) -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGCSImage.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGCSImage.kt deleted file mode 100644 index 79ed3fa186b..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGCSImage.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.ai.type - -/** - * 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"`). - */ -internal class ImagenGCSImage -internal constructor(public val gcsUri: String, public val mimeType: String) {} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationConfig.kt deleted file mode 100644 index 623adcc1ea4..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationConfig.kt +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.ai.type - -/** - * Contains extra settings to configure image generation. - * - * @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. - * @param imageFormat The file format/compression of the generated images. - * @param addWatermark Adds an invisible watermark to mark the image as AI generated. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -import kotlin.jvm.JvmField - -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -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, -) { - /** - * Builder for creating a [ImagenGenerationConfig]. - * - * This is mainly intended for Java interop. For Kotlin, use [imagenGenerationConfig] for a more - * idiomatic experience. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public class Builder { - @JvmField public var negativePrompt: String? = null - @JvmField public var numberOfImages: Int? = 1 - @JvmField public var aspectRatio: ImagenAspectRatio? = null - @JvmField public var imageFormat: ImagenImageFormat? = null - @JvmField public var addWatermark: Boolean? = null - - /** - * See [ImagenGenerationConfig.negativePrompt]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun setNegativePrompt(negativePrompt: String): Builder = apply { - this.negativePrompt = negativePrompt - } - - /** - * See [ImagenGenerationConfig.numberOfImages]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun setNumberOfImages(numberOfImages: Int): Builder = apply { - this.numberOfImages = numberOfImages - } - - /** - * See [ImagenGenerationConfig.aspectRatio]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun setAspectRatio(aspectRatio: ImagenAspectRatio): Builder = apply { - this.aspectRatio = aspectRatio - } - - /** - * See [ImagenGenerationConfig.imageFormat]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun setImageFormat(imageFormat: ImagenImageFormat): Builder = apply { - this.imageFormat = imageFormat - } - - /** - * See [ImagenGenerationConfig.addWatermark]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun setAddWatermark(addWatermark: Boolean): Builder = apply { - this.addWatermark = addWatermark - } - - /** - * Alternative casing for [ImagenGenerationConfig.Builder]: - * ``` - * val config = GenerationConfig.builder() - * ``` - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun build(): ImagenGenerationConfig = - ImagenGenerationConfig( - negativePrompt = negativePrompt, - numberOfImages = numberOfImages, - aspectRatio = aspectRatio, - imageFormat = imageFormat, - addWatermark = addWatermark, - ) - } - - public companion object { - public fun builder(): Builder = Builder() - } -} - -/** - * 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 - * } - * ``` - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public fun imagenGenerationConfig( - init: ImagenGenerationConfig.Builder.() -> Unit -): ImagenGenerationConfig { - val builder = ImagenGenerationConfig.builder() - builder.init() - return builder.build() -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationResponse.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationResponse.kt deleted file mode 100644 index 69101c49aeb..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenGenerationResponse.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.ai.type - -import android.util.Base64 -import com.google.firebase.ai.ImagenModel -import kotlinx.serialization.Serializable - -/** - * 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 - * the reason they were filtered out. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenGenerationResponse -internal constructor(public val images: List, public val filteredReason: String?) { - - @Serializable - internal data class Internal(val predictions: List) { - internal fun toPublicGCS() = - ImagenGenerationResponse( - images = predictions.filter { it.mimeType != null }.map { it.toPublicGCS() }, - null, - ) - - internal fun toPublicInline() = - ImagenGenerationResponse( - images = predictions.filter { it.mimeType != null }.map { it.toPublicInline() }, - predictions.firstNotNullOfOrNull { it.raiFilteredReason }, - ) - } - - @Serializable - internal data class ImagenImageResponse( - val bytesBase64Encoded: String? = null, - val gcsUri: String? = null, - val mimeType: String? = null, - val raiFilteredReason: String? = null, - val safetyAttributes: ImagenSafetyAttributes? = null, - ) { - internal fun toPublicInline() = - ImagenInlineImage(Base64.decode(bytesBase64Encoded!!, Base64.NO_WRAP), mimeType!!) - - internal fun toPublicGCS() = ImagenGCSImage(gcsUri!!, mimeType!!) - } - - @Serializable - internal data class ImagenSafetyAttributes( - val categories: List? = null, - val scores: List? = null - ) { - internal fun toPublic(): Map { - if (categories == null || scores == null) { - return emptyMap() - } - return categories.zip(scores).toMap() - } - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImageFormat.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImageFormat.kt deleted file mode 100644 index ffaed4d5258..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImageFormat.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -/** - * 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. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenImageFormat -private constructor(public val mimeType: String, public val compressionQuality: Int?) { - - internal fun toInternal() = Internal(mimeType, compressionQuality) - - @Serializable internal data class Internal(val mimeType: String, val compressionQuality: Int?) - - public companion object { - /** - * An [ImagenImageFormat] representing a JPEG 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. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmStatic - public fun jpeg(compressionQuality: Int? = null): ImagenImageFormat { - return ImagenImageFormat("image/jpeg", compressionQuality) - } - - /** - * An [ImagenImageFormat] representing a PNG image - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmStatic - public fun png(): ImagenImageFormat { - return ImagenImageFormat("image/png", null) - } - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImagePlacement.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImagePlacement.kt deleted file mode 100644 index e4c52586ec8..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImagePlacement.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents where the placement of an image is within a new, larger image, usually in the context - * of an outpainting request. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenImagePlacement -private constructor(public val x: Int? = null, public val y: Int? = null) { - - /** - * If this placement is represented by coordinates this is a no-op, if its one of the enumerated - * types below, then the position is calculated based on its description - */ - internal fun normalizeToDimensions( - imageDimensions: Dimensions, - canvasDimensions: Dimensions, - ): ImagenImagePlacement { - if (this.x != null && this.y != null) { - return this - } - val halfCanvasHeight = canvasDimensions.height / 2 - val halfCanvasWidth = canvasDimensions.width / 2 - val halfImageHeight = imageDimensions.height / 2 - val halfImageWidth = imageDimensions.width / 2 - return when (this) { - CENTER -> - ImagenImagePlacement(halfCanvasWidth - halfImageWidth, halfCanvasHeight - halfImageHeight) - TOP_CENTER -> ImagenImagePlacement(halfCanvasWidth - halfImageWidth, 0) - BOTTOM_CENTER -> - ImagenImagePlacement( - halfCanvasWidth - halfImageWidth, - canvasDimensions.height - imageDimensions.height, - ) - LEFT_CENTER -> ImagenImagePlacement(0, halfCanvasHeight - halfImageHeight) - RIGHT_CENTER -> - ImagenImagePlacement( - canvasDimensions.width - imageDimensions.width, - halfCanvasHeight - halfImageHeight, - ) - TOP_RIGHT -> ImagenImagePlacement(canvasDimensions.width - imageDimensions.width, 0) - BOTTOM_LEFT -> ImagenImagePlacement(0, canvasDimensions.height - imageDimensions.height) - BOTTOM_RIGHT -> - ImagenImagePlacement( - canvasDimensions.width - imageDimensions.width, - canvasDimensions.height - imageDimensions.height, - ) - else -> { - throw IllegalStateException("Unknown ImagenImagePlacement instance, cannot normalize") - } - } - } - - public companion object { - /** - * Creates an [ImagenImagePlacement] that represents a placement in an image described by two - * coordinates. The coordinate system has 0,0 in the top left corner, and the x and y - * coordinates represent the location of the top left corner of the original image. - * @param x the x coordinate of the top left corner of the original image - * @param y the y coordinate of the top left corner of the original image - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmStatic - public fun fromCoordinate(x: Int, y: Int): ImagenImagePlacement { - return ImagenImagePlacement(x, y) - } - - /** Center the image horizontally and vertically within the larger image */ - @JvmField public val CENTER: ImagenImagePlacement = ImagenImagePlacement() - - /** Center the image horizontally and aligned with the top edge of the larger image */ - @JvmField public val TOP_CENTER: ImagenImagePlacement = ImagenImagePlacement() - - /** Center the image horizontally and aligned with the bottom edge of the larger image */ - @JvmField public val BOTTOM_CENTER: ImagenImagePlacement = ImagenImagePlacement() - - /** Center the image vertically and aligned with the left edge of the larger image */ - @JvmField public val LEFT_CENTER: ImagenImagePlacement = ImagenImagePlacement() - - /** Center the image vertically and aligned with the right edge of the larger image */ - @JvmField public val RIGHT_CENTER: ImagenImagePlacement = ImagenImagePlacement() - - /** Align the image with the top left corner of the larger image */ - @JvmField public val TOP_LEFT: ImagenImagePlacement = ImagenImagePlacement(0, 0) - - /** Align the image with the top right corner of the larger image */ - @JvmField public val TOP_RIGHT: ImagenImagePlacement = ImagenImagePlacement() - - /** Align the image with the bottom left corner of the larger image */ - @JvmField public val BOTTOM_LEFT: ImagenImagePlacement = ImagenImagePlacement() - - /** Align the image with the bottom right corner of the larger image */ - @JvmField public val BOTTOM_RIGHT: ImagenImagePlacement = ImagenImagePlacement() - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenInlineImage.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenInlineImage.kt deleted file mode 100644 index e25b4e9b269..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenInlineImage.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.ai.type - -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.util.Base64 -import java.io.ByteArrayOutputStream -import kotlinx.serialization.Serializable - -/** - * Represents an Imagen-generated image that is returned as inline data. - * - * @property data The raw image bytes in JPEG or PNG format, as specified by [mimeType]. - * @property mimeType The IANA standard MIME type of the image data; either `"image/png"` or - * `"image/jpeg"`; to request a different format, see [ImagenGenerationConfig.imageFormat]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -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. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - public fun asBitmap(): Bitmap { - return BitmapFactory.decodeByteArray(data, 0, data.size) - } - - @Serializable internal data class Internal(val bytesBase64Encoded: String) - - internal fun toInternal(): Internal { - val base64 = Base64.encodeToString(data, Base64.NO_WRAP) - return Internal(base64) - } -} - -/** - * Helper method to convert an Android bitmap to an Imagen inline data image. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public fun Bitmap.toImagenInlineImage(): ImagenInlineImage { - val byteArrayOutputStream = ByteArrayOutputStream() - this.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream) - val byteArray = byteArrayOutputStream.toByteArray() - return ImagenInlineImage(data = byteArray, mimeType = "image/jpeg") -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskConfig.kt deleted file mode 100644 index 64a9a4376e3..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskConfig.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -internal class ImagenMaskConfig( - internal val maskType: ImagenMaskMode, - internal val dilation: Double? = null, - internal val classes: List? = null -) { - internal fun toInternal(): Internal { - return Internal(maskType.value, dilation, classes) - } - - @Serializable - internal data class Internal( - val maskMode: String, - val dilation: Double?, - val maskClasses: List? - ) -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskMode.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskMode.kt deleted file mode 100644 index b83a20381e2..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenMaskMode.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.ai.type - -internal class ImagenMaskMode private constructor(internal val value: String) { - companion object { - val USER_PROVIDED: ImagenMaskMode = ImagenMaskMode("MASK_MODE_USER_PROVIDED") - val BACKGROUND: ImagenMaskMode = ImagenMaskMode("MASK_MODE_BACKGROUND") - val FOREGROUND: ImagenMaskMode = ImagenMaskMode("MASK_MODE_FOREGROUND") - val SEMANTIC: ImagenMaskMode = ImagenMaskMode("MASK_MODE_SEMANTIC") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenPersonFilterLevel.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenPersonFilterLevel.kt deleted file mode 100644 index bc96d5d268d..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenPersonFilterLevel.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.ai.type - -/** - * A filter used to prevent images from containing depictions of children or people. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenPersonFilterLevel private constructor(internal val internalVal: String) { - public companion object { - /** - * Allow generation of images containing people of all ages. - * - * > Important: Generation of images containing people or faces may require your use case to be - * reviewed and approved by Cloud support; see the - * [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) - * for more details. - */ - @JvmField public val ALLOW_ALL: ImagenPersonFilterLevel = ImagenPersonFilterLevel("allow_all") - /** - * Allow generation of images containing adults only; images of children are filtered out. - * - * > Important: Generation of images containing people or faces may require your use case to be - * reviewed and approved by Cloud support; see the - * [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) - * for more details. - */ - @JvmField - public val ALLOW_ADULT: ImagenPersonFilterLevel = ImagenPersonFilterLevel("allow_adult") - /** - * Disallow generation of images containing people or faces; images of people are filtered out. - */ - @JvmField public val BLOCK_ALL: ImagenPersonFilterLevel = ImagenPersonFilterLevel("dont_allow") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt deleted file mode 100644 index 433ef63d3d8..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt +++ /dev/null @@ -1,365 +0,0 @@ -/* - * 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.ai.type - -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Paint -import android.graphics.Rect -import com.google.firebase.ai.common.GenerateImageRequest -import kotlinx.serialization.Serializable - -/** - * Represents an reference image for an Imagen editing request - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public abstract class ImagenReferenceImage -internal constructor( - internal val maskConfig: ImagenMaskConfig? = null, - internal val subjectConfig: ImagenSubjectConfig? = null, - internal val styleConfig: ImagenStyleConfig? = null, - internal val controlConfig: ImagenControlConfig? = null, - public val image: ImagenInlineImage? = null, - public val referenceId: Int? = null, -) { - - internal fun toInternal(optionalReferenceId: Int): Internal { - val referenceType = - when (this) { - is ImagenRawImage -> GenerateImageRequest.ReferenceType.RAW - is ImagenMaskReference -> GenerateImageRequest.ReferenceType.MASK - is ImagenSubjectReference -> GenerateImageRequest.ReferenceType.SUBJECT - is ImagenStyleReference -> GenerateImageRequest.ReferenceType.STYLE - is ImagenControlReference -> GenerateImageRequest.ReferenceType.CONTROL - else -> { - throw IllegalStateException( - "${this.javaClass.simpleName} is not a known subtype of ImagenReferenceImage" - ) - } - } - return Internal( - referenceType = referenceType, - referenceImage = image?.toInternal(), - referenceId = referenceId ?: optionalReferenceId, - subjectImageConfig = subjectConfig?.toInternal(), - maskImageConfig = maskConfig?.toInternal(), - styleImageConfig = styleConfig?.toInternal(), - controlConfig = controlConfig?.toInternal(), - ) - } - - @Serializable - internal data class Internal( - val referenceType: GenerateImageRequest.ReferenceType, - val referenceImage: ImagenInlineImage.Internal?, - val referenceId: Int, - val subjectImageConfig: ImagenSubjectConfig.Internal?, - val maskImageConfig: ImagenMaskConfig.Internal?, - val styleImageConfig: ImagenStyleConfig.Internal?, - val controlConfig: ImagenControlConfig.Internal? - ) -} - -/** - * Represents a reference image (provided or generated) to bound the created image via controlled - * generation. - * @param image the image provided, required if [enableComputation] is false - * @param type the type of control reference image - * @param referenceId the reference ID for this image, to be referenced in the prompt - * @param enableComputation requests that the reference image be generated serverside instead of - * provided - * @param superpixelRegionSize if type is [ImagenControlType.COLOR_SUPERPIXEL] and - * [enableComputation] is true, this will control the size of each superpixel region in pixels for - * the generated referenced image - * @param superpixelRuler if type is [ImagenControlType.COLOR_SUPERPIXEL] and [enableComputation] is - * true, this will control the superpixel smoothness factor for the generated referenced image - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenControlReference( - type: ImagenControlType, - image: ImagenInlineImage? = null, - referenceId: Int? = null, - enableComputation: Boolean? = null, - superpixelRegionSize: Int? = null, - superpixelRuler: Int? = null, -) : - ImagenReferenceImage( - controlConfig = - ImagenControlConfig(type, enableComputation, superpixelRegionSize, superpixelRuler), - image = image, - referenceId = referenceId, - ) {} - -/** - * Represents a mask for Imagen editing. This image (generated or provided) should contain only - * black and white pixels, with black representing parts of the image which should not change. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public abstract class ImagenMaskReference -internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = null) : - ImagenReferenceImage(maskConfig = maskConfig, image = image) { - - public companion object { - /** - * Generates two reference images of [ImagenRawImage] and [ImagenRawMask]. These images are - * generated in this order: - * * One [ImagenRawImage] containing the original image, padded out to the new dimensions with - * black pixels, with the original image placed at the given placement - * * One [ImagenRawMask] of the same dimensions containing white everywhere except at the - * placement original image. This is the format expected by Imagen for outpainting requests. - * - * @param image the original image - * @param newDimensions the new dimensions for outpainting. These new dimensions *must* be more - * than the original image. - * @param newPosition the placement of the original image within the new outpainted image. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmOverloads - @JvmStatic - public fun generateMaskAndPadForOutpainting( - image: ImagenInlineImage, - newDimensions: Dimensions, - newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, - ): List = - generateMaskAndPadForOutpainting(image, newDimensions, newPosition, 0.01) - - /** - * Generates two reference images of [ImagenRawImage] and [ImagenRawMask]. These images are - * generated in this order: - * * One [ImagenRawImage] containing the original image, padded out to the new dimensions with - * black pixels, with the original image placed at the given placement - * * One [ImagenRawMask] of the same dimensions containing white everywhere except at the - * placement original image. This is the format expected by Imagen for outpainting requests. - * - * @param image the original image - * @param newDimensions the new dimensions for outpainting. These new dimensions *must* be more - * than the original image. - * @param newPosition the placement of the original image within the new outpainted image. - * @param dilation the dilation for the outpainting mask. See: [ImagenRawMask]. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as - * early as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ - @Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") - @JvmStatic - public fun generateMaskAndPadForOutpainting( - image: ImagenInlineImage, - newDimensions: Dimensions, - newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, - dilation: Double = 0.01 - ): List { - val originalBitmap = image.asBitmap() - if ( - originalBitmap.width > newDimensions.width || originalBitmap.height > newDimensions.height - ) { - throw IllegalArgumentException( - "New Dimensions must be strictly larger than original image dimensions. Original image " + - "is:${originalBitmap.width}x${originalBitmap.height}, new dimensions are " + - "${newDimensions.width}x${newDimensions.height}" - ) - } - val normalizedPosition = - newPosition.normalizeToDimensions( - Dimensions(originalBitmap.width, originalBitmap.height), - newDimensions, - ) - - if (normalizedPosition.x == null || normalizedPosition.y == null) { - throw IllegalStateException("Error normalizing position for mask and padding.") - } - - val normalizedImageRectangle = - Rect( - normalizedPosition.x, - normalizedPosition.y, - normalizedPosition.x + originalBitmap.width, - normalizedPosition.y + originalBitmap.height, - ) - - val maskBitmap = - Bitmap.createBitmap(newDimensions.width, newDimensions.height, Bitmap.Config.RGB_565) - val newImageBitmap = - Bitmap.createBitmap(newDimensions.width, newDimensions.height, Bitmap.Config.RGB_565) - - val maskCanvas = Canvas(maskBitmap) - val newImageCanvas = Canvas(newImageBitmap) - - val blackPaint = Paint().apply { color = Color.BLACK } - val whitePaint = Paint().apply { color = Color.WHITE } - - // Fill the mask with white, then draw a black rectangle where the image is. - maskCanvas.drawPaint(whitePaint) - maskCanvas.drawRect(normalizedImageRectangle, blackPaint) - - // fill the image with black, and then draw the bitmap into the corresponding spot - newImageCanvas.drawPaint(blackPaint) - newImageCanvas.drawBitmap(originalBitmap, null, normalizedImageRectangle, null) - return listOf( - ImagenRawImage(newImageBitmap.toImagenInlineImage()), - ImagenRawMask(maskBitmap.toImagenInlineImage(), dilation), - ) - } - } -} - -/** - * A generated mask image which will auto-detect and mask out the background. The background will be - * white, and the foreground black - * @param dilation the amount to dilate the mask. This can help smooth the borders of an edit and - * make it seem more convincing. For example, `0.05` will dilate the mask 5%. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenBackgroundMask(dilation: Double? = null) : - ImagenMaskReference(maskConfig = ImagenMaskConfig(ImagenMaskMode.BACKGROUND, dilation)) {} - -/** - * A generated mask image which will auto-detect and mask out the foreground. The background will be - * black, and the foreground white - * @param dilation the amount to dilate the mask. This can help smooth the borders of an edit and - * make it seem more convincing. For example, `0.05` will dilate the mask 5%. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenForegroundMask(dilation: Double? = null) : - ImagenMaskReference(maskConfig = ImagenMaskConfig(ImagenMaskMode.FOREGROUND, dilation)) {} - -/** - * Represents a mask for Imagen editing. This image should contain only black and white pixels, with - * black representing parts of the image which should not change. - * - * @param mask the mask image - * @param dilation the amount to dilate the mask. This can help smooth the borders of an edit and - * make it seem more convincing. For example, `0.05` will dilate the mask 5%. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenRawMask(mask: ImagenInlineImage, dilation: Double? = null) : - ImagenMaskReference( - maskConfig = ImagenMaskConfig(ImagenMaskMode.USER_PROVIDED, dilation), - image = mask, - ) {} - -/** - * Represents a generated mask for Imagen editing which masks out certain objects using object - * detection. - * @param classes the list of segmentation IDs for objects to detect and mask out. Find a - * [list of segmentation IDs](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api-edit#segment-ids) - * in the Vertex AI documentation. - * @param dilation the amount to dilate the mask. This can help smooth the borders of an edit and - * make it seem more convincing. For example, `0.05` will dilate the mask 5%. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenSemanticMask(classes: List, dilation: Double? = null) : - ImagenMaskReference(maskConfig = ImagenMaskConfig(ImagenMaskMode.SEMANTIC, dilation, classes)) {} - -/** - * Represents a base image for Imagen editing - * @param image the image - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenRawImage(image: ImagenInlineImage) : ImagenReferenceImage(image = image) {} - -/** - * A reference image for style transfer - * @param image the image representing the style you want to transfer to your original images - * @param referenceId the reference ID you can use to reference this style in your prompt - * @param description the description you can use to reference this style in your prompt - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenStyleReference( - image: ImagenInlineImage, - referenceId: Int? = null, - description: String? = null, -) : - ImagenReferenceImage( - image = image, - referenceId = referenceId, - styleConfig = ImagenStyleConfig(description) - ) {} - -/** - * A reference image for generating an image with a specific subject - * @param image the image of the subject - * @param referenceId the reference ID you can use to reference this subject in your prompt - * @param description the description you can use to reference this subject in your prompt - * @param subjectType the type of the subject - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -@PublicPreviewAPI -public class ImagenSubjectReference( - image: ImagenInlineImage, - referenceId: Int? = null, - description: String? = null, - subjectType: ImagenSubjectReferenceType? = null, -) : - ImagenReferenceImage( - image = image, - referenceId = referenceId, - subjectConfig = ImagenSubjectConfig(description, subjectType), - ) {} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetyFilterLevel.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetyFilterLevel.kt deleted file mode 100644 index acd48d2669c..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetyFilterLevel.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.ai.type - -/** - * Used for safety filtering. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenSafetyFilterLevel private constructor(internal val internalVal: String) { - public companion object { - /** Strongest filtering level, most strict blocking. */ - @JvmField - public val BLOCK_LOW_AND_ABOVE: ImagenSafetyFilterLevel = - ImagenSafetyFilterLevel("block_low_and_above") - /** Block some problematic prompts and responses. */ - @JvmField - public val BLOCK_MEDIUM_AND_ABOVE: ImagenSafetyFilterLevel = - ImagenSafetyFilterLevel("block_medium_and_above") - /** - * Reduces the number of requests blocked due to safety filters. May increase objectionable - * content generated by the Imagen model. - */ - @JvmField - public val BLOCK_ONLY_HIGH: ImagenSafetyFilterLevel = ImagenSafetyFilterLevel("block_only_high") - /** Turns off all optional safety filters. */ - @JvmField public val BLOCK_NONE: ImagenSafetyFilterLevel = ImagenSafetyFilterLevel("block_none") - } -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetySettings.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetySettings.kt deleted file mode 100644 index 89e0eea3bd0..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSafetySettings.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.ai.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. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -public class ImagenSafetySettings( - internal val safetyFilterLevel: ImagenSafetyFilterLevel, - internal val personFilterLevel: ImagenPersonFilterLevel, -) {} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenStyleConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenStyleConfig.kt deleted file mode 100644 index 222f9b3f5a3..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenStyleConfig.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -internal class ImagenStyleConfig(val description: String?) { - - fun toInternal(): Internal { - return Internal(description) - } - - @Serializable internal data class Internal(val styleDescription: String?) -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectConfig.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectConfig.kt deleted file mode 100644 index 603a580a25e..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectConfig.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.ai.type - -import kotlinx.serialization.Serializable - -internal class ImagenSubjectConfig( - val description: String?, - val type: ImagenSubjectReferenceType?, -) { - - internal fun toInternal(): Internal { - return Internal(description, type?.value) - } - - @Serializable - internal data class Internal(val subjectDescription: String?, val subjectType: String?) -} diff --git a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectReferenceType.kt b/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectReferenceType.kt deleted file mode 100644 index 8457bc8ab4d..00000000000 --- a/ai-logic/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenSubjectReferenceType.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.ai.type - -/** - * Represents a type for a subject reference, specifying how it should be interpreted. - * - * @deprecated **Deprecation Notice:** All Imagen models are deprecated and will shut down as early - * as June 2026. As a replacement, you can - * [migrate your apps to use Gemini Image models (the 'Nano Banana' models)](https://firebase.google.com/docs/ai-logic/imagen-models-migration) - */ -@Deprecated("All Imagen models are deprecated. Migrate your apps to use Gemini Image Models") -public class ImagenSubjectReferenceType private constructor(internal val value: String) { - - public companion object { - - /** Marks the reference type as being of a person */ - @JvmField - public val PERSON: ImagenSubjectReferenceType = - ImagenSubjectReferenceType("SUBJECT_TYPE_PERSON") - - /** Marks the reference type as being of a animal */ - @JvmField - public val ANIMAL: ImagenSubjectReferenceType = - ImagenSubjectReferenceType("SUBJECT_TYPE_ANIMAL") - - /** Marks the reference type as being of a product */ - @JvmField - public val PRODUCT: ImagenSubjectReferenceType = - ImagenSubjectReferenceType("SUBJECT_TYPE_PRODUCT") - } -} diff --git a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/SerializationTests.kt b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/SerializationTests.kt index cbc575d11ed..8047cc48eb2 100644 --- a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/SerializationTests.kt +++ b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/SerializationTests.kt @@ -17,7 +17,6 @@ package com.google.firebase.ai import com.google.firebase.ai.common.TemplateGenerateContentRequest -import com.google.firebase.ai.common.TemplateGenerateImageRequest import com.google.firebase.ai.common.util.descriptorToJson import com.google.firebase.ai.type.Candidate import com.google.firebase.ai.type.CountTokensResponse @@ -28,7 +27,6 @@ import com.google.firebase.ai.type.GroundingChunk import com.google.firebase.ai.type.GroundingMetadata import com.google.firebase.ai.type.GroundingSupport import com.google.firebase.ai.type.ImageConfig -import com.google.firebase.ai.type.ImagenReferenceImage import com.google.firebase.ai.type.LiveServerGoAway import com.google.firebase.ai.type.ModalityTokenCount import com.google.firebase.ai.type.PublicPreviewAPI @@ -484,43 +482,6 @@ internal class SerializationTests { expectedJsonAsString shouldEqualJson actualJson.toString() } - @Test - fun `test ReferenceImage serialization as Json`() { - val expectedJsonAsString = - """ - { - "id": "ImagenReferenceImage", - "type": "object", - "properties": { - "referenceType": { - "type": "string" - }, - "referenceImage": { - "${'$'}ref": "ImagenInlineImage" - }, - "referenceId": { - "type": "integer" - }, - "subjectImageConfig": { - "${'$'}ref": "ImagenSubjectConfig" - }, - "maskImageConfig": { - "${'$'}ref": "ImagenMaskConfig" - }, - "styleImageConfig": { - "${'$'}ref": "ImagenStyleConfig" - }, - "controlConfig": { - "${'$'}ref": "ImagenControlConfig" - } - } - } - """ - .trimIndent() - val actualJson = descriptorToJson(ImagenReferenceImage.Internal.serializer().descriptor) - expectedJsonAsString shouldEqualJson actualJson.toString() - } - @Test fun `test Tool serialization as Json`() { val expectedJsonAsString = @@ -595,28 +556,6 @@ internal class SerializationTests { expectedJsonAsString shouldEqualJson actualJson.toString() } - @Test - fun `test template imagen request serialization as Json`() { - val expectedJsonAsString = - """ - { - "id": "TemplateGenerateImageRequest", - "type": "object", - "properties": { - "inputs": { - "type": "object", - "additionalProperties": { - "${"$"}ref": "JsonElement" - } - } - } - } - """ - .trimIndent() - val actualJson = descriptorToJson(TemplateGenerateImageRequest.serializer().descriptor) - expectedJsonAsString shouldEqualJson actualJson.toString() - } - @Test fun `test GoogleSearch serialization as Json`() { val expectedJsonAsString = diff --git a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIUnarySnapshotTests.kt b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIUnarySnapshotTests.kt index 297bdfa25c4..1a885f4e3d6 100644 --- a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIUnarySnapshotTests.kt +++ b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/VertexAIUnarySnapshotTests.kt @@ -18,7 +18,6 @@ package com.google.firebase.ai import com.google.firebase.ai.type.AutoFunctionDeclaration import com.google.firebase.ai.type.BlockReason -import com.google.firebase.ai.type.ContentBlockedException import com.google.firebase.ai.type.ContentModality import com.google.firebase.ai.type.FinishReason import com.google.firebase.ai.type.FunctionCallPart @@ -626,34 +625,6 @@ internal class VertexAIUnarySnapshotTests { withTimeout(testTimeout) { shouldThrow { model.countTokens("prompt") } } } - @Test - fun `generateImages should throw when all images filtered`() = - goldenVertexUnaryFile("unary-failure-generate-images-all-filtered.json") { - withTimeout(testTimeout) { - shouldThrow { imagenModel.generateImages("prompt") } - } - } - - @Test - fun `generateImages should throw when prompt blocked`() = - goldenVertexUnaryFile( - "unary-failure-generate-images-prompt-blocked.json", - HttpStatusCode.BadRequest, - ) { - withTimeout(testTimeout) { - shouldThrow { imagenModel.generateImages("prompt") } - } - } - - @Test - fun `generateImages should contain safety data`() = - goldenVertexUnaryFile("unary-success-generate-images-safety_info.json") { - withTimeout(testTimeout) { - val response = imagenModel.generateImages("prompt") - // There is no public API, but if it parses then success - } - } - @Test fun `google search grounding metadata is parsed correctly`() = goldenVertexUnaryFile("unary-success-google-search-grounding.json") { diff --git a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt index 742b9e494cb..e4a870b1869 100644 --- a/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt +++ b/ai-logic/firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt @@ -22,7 +22,6 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import com.google.firebase.FirebaseApp import com.google.firebase.ai.GenerativeModel -import com.google.firebase.ai.ImagenModel import com.google.firebase.ai.common.APIController import com.google.firebase.ai.common.util.TEST_MODEL_NAME import com.google.firebase.ai.generativemodel.CloudGenerativeModelProvider @@ -72,7 +71,6 @@ internal suspend fun ByteChannel.send(bytes: ByteArray) { */ internal data class CommonTestScope( val model: GenerativeModel, - val imagenModel: ImagenModel, ) internal data class ResponseInfo( @@ -147,8 +145,7 @@ internal fun commonTest( requestOptions = RequestOptions(), tools = tools ) - val imagenModel = ImagenModel("cooler-model-name", controller = apiController) - CommonTestScope(model, imagenModel).block() + CommonTestScope(model).block() } /** @@ -223,8 +220,7 @@ internal fun commonMultiTurnTest( requestOptions = requestOptions, tools = tools ) - val imagenModel = ImagenModel("cooler-model-name", controller = apiController) - CommonTestScope(model, imagenModel).block() + CommonTestScope(model).block() } /** diff --git a/ai-logic/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java b/ai-logic/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java index dbf7bb0f14a..423060dd779 100644 --- a/ai-logic/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java +++ b/ai-logic/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.firebase.ai.FirebaseAI; import com.google.firebase.ai.GenerativeModel; -import com.google.firebase.ai.ImagenModel; import com.google.firebase.ai.InferenceMode; import com.google.firebase.ai.LiveGenerativeModel; import com.google.firebase.ai.OnDeviceConfig; @@ -29,7 +28,6 @@ import com.google.firebase.ai.TemplateGenerativeModel; import com.google.firebase.ai.java.ChatFutures; import com.google.firebase.ai.java.GenerativeModelFutures; -import com.google.firebase.ai.java.ImagenModelFutures; import com.google.firebase.ai.java.LiveModelFutures; import com.google.firebase.ai.java.LiveSessionFutures; import com.google.firebase.ai.java.TemplateChatFutures; @@ -43,7 +41,6 @@ import com.google.firebase.ai.type.Content; import com.google.firebase.ai.type.ContentModality; import com.google.firebase.ai.type.CountTokensResponse; -import com.google.firebase.ai.type.Dimensions; import com.google.firebase.ai.type.FileDataPart; import com.google.firebase.ai.type.FinishReason; import com.google.firebase.ai.type.FunctionCallPart; @@ -56,11 +53,6 @@ import com.google.firebase.ai.type.ImageConfig; import com.google.firebase.ai.type.ImagePart; import com.google.firebase.ai.type.ImageSize; -import com.google.firebase.ai.type.ImagenBackgroundMask; -import com.google.firebase.ai.type.ImagenEditMode; -import com.google.firebase.ai.type.ImagenEditingConfig; -import com.google.firebase.ai.type.ImagenInlineImage; -import com.google.firebase.ai.type.ImagenMaskReference; import com.google.firebase.ai.type.InlineData; import com.google.firebase.ai.type.InlineDataPart; import com.google.firebase.ai.type.LatLng; @@ -210,17 +202,6 @@ private LiveGenerationConfig getLiveConfig() { .build(); } - private void testImagen() { - ImagenModel modelSuspend = FirebaseAI.getInstance().imagenModel(""); - ImagenModelFutures model = ImagenModelFutures.from(modelSuspend); - model.editImage( - Collections.singletonList(new ImagenBackgroundMask()), - "", - new ImagenEditingConfig(ImagenEditMode.OUTPAINT, 25)); - ImagenMaskReference.generateMaskAndPadForOutpainting( - new ImagenInlineImage(new byte[0], ""), new Dimensions(0, 0)); - } - private void testSpeechConfig() { SpeechConfig singleSpeechConfig = new SpeechConfig(new Voice("Charon"), "en-US");