-
Notifications
You must be signed in to change notification settings - Fork 403
Rebrand Vertex AI -> Agent Platform in the Android AI sample #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,17 +28,17 @@ | |
|
|
||
| import java.util.concurrent.Executor; | ||
|
|
||
| public class VertexAiGeminiApiJava { | ||
| public class AgentPlatformGeminiApiJava { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -37,6 +37,14 @@ object GeminiDeveloperApi25FlashModelConfiguration { | |
| // [END android_gemini_developer_api_gemini_25_flash_model] | ||
| } | ||
|
|
||
| object GeminiDeveloperApi35FlashModelConfiguration { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
|
@@ -52,9 +60,24 @@ object Gemini25FlashImagePreviewModelConfiguration { | |
| // [END android_gemini_developer_api_gemini_25_flash_image_model] | ||
| } | ||
|
|
||
| object Gemini35FlashImagePreviewModelConfiguration { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") | ||
|
|
@@ -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( | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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( | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
|
|
@@ -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] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") | ||
|
|
@@ -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) | ||
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -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"); | ||
|
|
@@ -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() | ||
|
|
@@ -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); | ||
|
|
@@ -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); | ||
|
|
||
There was a problem hiding this comment.
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.