Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import com.google.firebase.ai.GenerativeModel
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.GenerativeBackend

class VertexAiGeminiApi {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you actually keep a copy of VertexAiGeminiApi in the repo with the old region tags? Then once you update DAC, you could delete that old file.

class AgentPlatformGeminiApi {

// [START android_snippets_vertex_ai_gemini_api_model]
val model = Firebase.ai(backend = GenerativeBackend.vertexAI())
.generativeModel("gemini-2.5-flash")
// [END android_snippets_vertex_ai_gemini_api_model]
// [START android_snippets_agent_platform_gemini_api_model]
val model = Firebase.ai(backend = GenerativeBackend.agentPlatform())
.generativeModel("gemini-3.5-flash")
// [END android_snippets_agent_platform_gemini_api_model]

// [START android_snippets_vertex_ai_generate_content]
// [START android_snippets_platform_agent_generate_content]
suspend fun generateText(model: GenerativeModel) {
// Note: generateContent() is a suspend function, which integrates well
// with existing Kotlin code.
val response = model.generateContent("Write a story about a magic backpack.")
// ...
}
// [END android_snippets_vertex_ai_generate_content]
// [END android_snippets_platform_agent_generate_content]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@

import java.util.concurrent.Executor;

public class VertexAiGeminiApiJava {
public class AgentPlatformGeminiApiJava {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this file, suggest keeping a copy of VertexAiGeminiApiJava until DAC successfully points to the new snippets.


// [START android_snippets_vertex_ai_gemini_api_model_java]
GenerativeModel firebaseAI = FirebaseAI.getInstance(GenerativeBackend.vertexAI())
.generativeModel("gemini-2.5-flash");
// [START android_snippets_agent_platform_gemini_api_model_java]
GenerativeModel firebaseAI = FirebaseAI.getInstance(GenerativeBackend.agentPlatform())
.generativeModel("gemini-3.5-flash");

GenerativeModelFutures model = GenerativeModelFutures.from(firebaseAI);
// [END android_snippets_vertex_ai_gemini_api_model_java]
// [END android_snippets_agent_platform_gemini_api_model_java]

void generateText(Executor executor) {
// [START android_snippets_vertex_ai_generate_content_java]
// [START android_snippets_agent_platform_generate_content_java]
Content prompt = new Content.Builder()
.addText("Write a story about a magic backpack.")
.build();
Expand All @@ -56,6 +56,6 @@ public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
// [END android_snippets_vertex_ai_generate_content_java]
// [END android_snippets_agent_platform_generate_content_java]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ object GeminiDeveloperApi25FlashModelConfiguration {
// [END android_gemini_developer_api_gemini_25_flash_model]
}

object GeminiDeveloperApi35FlashModelConfiguration {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove the 35 so it's not tied to a release number?

// [START android_gemini_developer_api_gemini_flash_model]
// Start by instantiating a GenerativeModel and specifying the model name:
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel("gemini-3.5-flash")
// [END android_gemini_developer_api_gemini_flash_model]
}

object Gemini25FlashImagePreviewModelConfiguration {
// [START android_gemini_developer_api_gemini_25_flash_image_model]
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
Expand All @@ -52,9 +60,24 @@ object Gemini25FlashImagePreviewModelConfiguration {
// [END android_gemini_developer_api_gemini_25_flash_image_model]
}

object Gemini35FlashImagePreviewModelConfiguration {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, remove 35 in the object name?

// [START android_gemini_developer_api_gemini_flash_image_model]
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3.5-flash-image-preview",
// Configure the model to respond with text and images (required)
generationConfig = generationConfig {
responseModalities = listOf(
ResponseModality.TEXT,
ResponseModality.IMAGE
)
}
)
// [END android_gemini_developer_api_gemini_flash_image_model]
}

@Suppress("unused")
fun textOnlyInput(scope: CoroutineScope) {
val model = GeminiDeveloperApi25FlashModelConfiguration.model
val model = GeminiDeveloperApi35FlashModelConfiguration.model
// [START android_gemini_developer_api_text_only_input]
scope.launch {
val response = model.generateContent("Write a story about a magic backpack.")
Expand All @@ -64,7 +87,7 @@ fun textOnlyInput(scope: CoroutineScope) {

@Suppress("unused")
fun textAndImageInput(scope: CoroutineScope, bitmap: Bitmap) {
val model = GeminiDeveloperApi25FlashModelConfiguration.model
val model = GeminiDeveloperApi35FlashModelConfiguration.model
// [START android_gemini_developer_api_multimodal_input]
scope.launch {
val response = model.generateContent(
Expand All @@ -83,7 +106,7 @@ fun textAndAudioInput(
applicationContext: Application,
audioUri: Uri
) {
val model = GeminiDeveloperApi25FlashModelConfiguration.model
val model = GeminiDeveloperApi35FlashModelConfiguration.model
// [START android_gemini_developer_api_multimodal_audio_input]
scope.launch {
val contentResolver = applicationContext.contentResolver
Expand All @@ -109,7 +132,7 @@ fun textAndVideoInput(
applicationContext: Application,
videoUri: Uri
) {
val model = GeminiDeveloperApi25FlashModelConfiguration.model
val model = GeminiDeveloperApi35FlashModelConfiguration.model
// [START android_gemini_developer_api_multimodal_video_input]
scope.launch {
val contentResolver = applicationContext.contentResolver
Expand All @@ -131,7 +154,7 @@ fun textAndVideoInput(

@Suppress("unused")
fun multiTurnChat(scope: CoroutineScope) {
val model = GeminiDeveloperApi25FlashModelConfiguration.model
val model = GeminiDeveloperApi35FlashModelConfiguration.model
// [START android_gemini_developer_api_multiturn_chat]
val chat = model.startChat(
history = listOf(
Expand All @@ -148,7 +171,7 @@ fun multiTurnChat(scope: CoroutineScope) {

@Suppress("unused")
fun generateImageFromText(scope: CoroutineScope) {
val model = Gemini25FlashImagePreviewModelConfiguration.model
val model = Gemini35FlashImagePreviewModelConfiguration.model
// [START android_gemini_developer_api_generate_image_from_text]
scope.launch {
// Provide a text prompt instructing the model to generate an image
Expand All @@ -164,7 +187,7 @@ fun generateImageFromText(scope: CoroutineScope) {

@Suppress("unused")
fun editImage(scope: CoroutineScope, bitmap: Bitmap) {
val model = Gemini25FlashImagePreviewModelConfiguration.model
val model = Gemini35FlashImagePreviewModelConfiguration.model
// [START android_gemini_developer_api_edit_image]
scope.launch {
// Provide a text prompt instructing the model to edit the image
Expand All @@ -182,7 +205,7 @@ fun editImage(scope: CoroutineScope, bitmap: Bitmap) {

@Suppress("unused")
fun editImageWithChat(scope: CoroutineScope, bitmap: Bitmap) {
val model = Gemini25FlashImagePreviewModelConfiguration.model
val model = Gemini35FlashImagePreviewModelConfiguration.model
// [START android_gemini_developer_api_edit_image_chat]
scope.launch {
// Create the initial prompt instructing the model to edit the image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ static final class GeminiDeveloperApi25FlashModelConfigurationJava {
}
}

static final class GeminiDeveloperApi35FlashModelConfigurationJava {
public static GenerativeModelFutures model;

static {
// [START android_gemini_developer_api_gemini_flash_model_java]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are new snippets, consider not migrating the java snippets here

GenerativeModel firebaseAI = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-3.5-flash");

GenerativeModelFutures model = GenerativeModelFutures.from(firebaseAI);
// [END android_gemini_developer_api_gemini_flash_model_java]
GeminiDeveloperApi35FlashModelConfigurationJava.model = model;
}
}

static final class Gemini25FlashImagePreviewModelConfigurationJava {
public static GenerativeModelFutures model;

Expand All @@ -86,11 +100,29 @@ static final class Gemini25FlashImagePreviewModelConfigurationJava {
// [END android_gemini_developer_api_gemini_25_flash_image_model_java]
Gemini25FlashImagePreviewModelConfigurationJava.model = model;
}
}

static final class Gemini35FlashImagePreviewModelConfigurationJava {
public static GenerativeModelFutures model;

static {
// [START android_gemini_developer_api_gemini_flash_image_model_java]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, do you want the java snippet added to the repo?

GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"gemini-3.5-flash-image-preview",
// Configure the model to respond with text and images (required)
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.TEXT, ResponseModality.IMAGE))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// [END android_gemini_developer_api_gemini_flash_image_model_java]
Gemini35FlashImagePreviewModelConfigurationJava.model = model;
}

}

public static void textOnlyInput(Executor executor) {
GenerativeModelFutures model = GeminiDeveloperApi25FlashModelConfigurationJava.model;
GenerativeModelFutures model = GeminiDeveloperApi35FlashModelConfigurationJava.model;
// [START android_gemini_developer_api_text_only_input_java]
Content prompt = new Content.Builder()
.addText("Write a story about a magic backpack.")
Expand All @@ -112,7 +144,7 @@ public void onFailure(Throwable t) {
}

public static void textAndImageInput(Executor executor, Bitmap bitmap) {
GenerativeModelFutures model = GeminiDeveloperApi25FlashModelConfigurationJava.model;
GenerativeModelFutures model = GeminiDeveloperApi35FlashModelConfigurationJava.model;
// [START android_gemini_developer_api_multimodal_input_java]
Content content = new Content.Builder()
.addImage(bitmap)
Expand All @@ -135,7 +167,7 @@ public void onFailure(Throwable t) {
}

public static void textAndAudioInput(Executor executor, Application applicationContext, Uri audioUri) {
GenerativeModelFutures model = GeminiDeveloperApi25FlashModelConfigurationJava.model;
GenerativeModelFutures model = GeminiDeveloperApi35FlashModelConfigurationJava.model;
// [START android_gemini_developer_api_multimodal_audio_input_java]
ContentResolver resolver = applicationContext.getContentResolver();

Expand Down Expand Up @@ -179,7 +211,7 @@ public void onFailure(Throwable t) {
}

public static void textAndVideoInput(Executor executor, Application applicationContext, Uri videoUri) {
GenerativeModelFutures model = GeminiDeveloperApi25FlashModelConfigurationJava.model;
GenerativeModelFutures model = GeminiDeveloperApi35FlashModelConfigurationJava.model;
// [START android_gemini_developer_api_multimodal_video_input_java]
ContentResolver resolver = applicationContext.getContentResolver();

Expand Down Expand Up @@ -221,7 +253,7 @@ public void onFailure(Throwable t) {
}

public static void multiTurnChat(Executor executor) {
GenerativeModelFutures model = GeminiDeveloperApi25FlashModelConfigurationJava.model;
GenerativeModelFutures model = GeminiDeveloperApi35FlashModelConfigurationJava.model;
// [START android_gemini_developer_api_multiturn_chat_java]
Content.Builder userContentBuilder = new Content.Builder();
userContentBuilder.setRole("user");
Expand Down Expand Up @@ -263,7 +295,7 @@ public void onFailure(Throwable t) {
}

public static void generateImageFromText(Executor executor) {
GenerativeModelFutures model = Gemini25FlashImagePreviewModelConfigurationJava.model;
GenerativeModelFutures model = Gemini35FlashImagePreviewModelConfigurationJava.model;
// [START android_gemini_developer_api_generate_image_from_text_java]
// Provide a text prompt instructing the model to generate an image
Content prompt = new Content.Builder()
Expand Down Expand Up @@ -293,7 +325,7 @@ public void onFailure(Throwable t) {
}

public static void editImage(Executor executor, Resources resources) {
GenerativeModelFutures model = Gemini25FlashImagePreviewModelConfigurationJava.model;
GenerativeModelFutures model = Gemini35FlashImagePreviewModelConfigurationJava.model;
// [START android_gemini_developer_api_edit_image_java]
// Provide an image for the model to edit
Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.scones);
Expand Down Expand Up @@ -325,7 +357,7 @@ public void onFailure(Throwable t) {
}

public static void editImageWithChat(Executor executor, Resources resources) {
GenerativeModelFutures model = Gemini25FlashImagePreviewModelConfigurationJava.model;
GenerativeModelFutures model = Gemini35FlashImagePreviewModelConfigurationJava.model;
// [START android_gemini_developer_api_edit_image_chat_java]
// Provide an image for the model to edit
Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.scones);
Expand Down
4 changes: 2 additions & 2 deletions ai/src/main/java/com/example/snippets/ai/GeminiOverview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class GeminiOverview {

suspend fun generateContent() {
// [START android_gemini_ai_models_overview]
// For Vertex AI, use `backend = GenerativeBackend.vertexAI()`
// For the Agent Platform Gemini API, use `backend = GenerativeBackend.agentPlatform()`
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel("gemini-2.5-flash")
.generativeModel("gemini-3.5-flash")

val response = model.generateContent("Write a story about a magic backpack")
val output = response.text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class GeminiOverviewJava {

void generateContent(Executor executor) {
// [START android_gemini_ai_models_overview_java]
// For Vertex AI, use `backend = GenerativeBackend.vertexAI()`
// For the Agent Platform Gemini API, use `backend = GenerativeBackend.agentPlatform()`
GenerativeModel firebaseAI = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-2.5-flash");
.generativeModel("gemini-3.5-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ datastoreCore = "1.2.1"
datastorePreferencesRxjava2 = "1.2.1"
datastorePreferencesRxjava3 = "1.2.1"
engageCore = "1.6.0"
firebase-ai = "17.13.0"
firebase-bom = "34.15.0"
firebase-ai = "17.15.0"
firebase-bom = "34.17.0"
firebase-ondevice = "16.0.0-beta03"
glance-wear = "1.0.0-alpha12"
glide = "1.0.0-beta09"
Expand Down
Loading