-
Notifications
You must be signed in to change notification settings - Fork 276
Add Gemini Developer API code snippets #649
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
Conversation
6449cbe
to
61a97f5
Compare
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.
Thanks for doing this, Cartland!
61a97f5
to
e04c9fd
Compare
This commit introduces a collection of code snippets demonstrating the usage of the Gemini Developer API. It includes examples for model configuration, text-only and multimodal inputs (image, audio, video), multi-turn chat, and image generation/editing. The necessary dependencies for Firebase AI, Guava, and Reactive Streams have been added to gradle/libs.versions.toml and misc/build.gradle.kts. Region-Tag: android_gemini_developer_api_gemini_25_flash_model Region-Tag: android_gemini_developer_api_gemini_25_flash_image_model Region-Tag: android_gemini_developer_api_text_only_input Region-Tag: android_gemini_developer_api_multimodal_input Region-Tag: android_gemini_developer_api_multimodal_audio_input Region-Tag: android_gemini_developer_api_multimodal_video_input Region-Tag: android_gemini_developer_api_multiturn_chat Region-Tag: android_gemini_developer_api_generate_image_from_text Region-Tag: android_gemini_developer_api_edit_image Region-Tag: android_gemini_developer_api_edit_image_chat Region-Tag: android_gemini_developer_api_gemini_25_flash_model_java Region-Tag: android_gemini_developer_api_gemini_25_flash_image_model_java Region-Tag: android_gemini_developer_api_text_only_input_java Region-Tag: android_gemini_developer_api_multimodal_input_java Region-Tag: android_gemini_developer_api_multimodal_audio_input_java Region-Tag: android_gemini_developer_api_multimodal_video_input_java Region-Tag: android_gemini_developer_api_multiturn_chat_java Region-Tag: android_gemini_developer_api_generate_image_from_text_java Region-Tag: android_gemini_developer_api_edit_image_java Region-Tag: android_gemini_developer_api_edit_image_chat_java
This commit adds new Kotlin snippets for the Firebase AI Imagen API. The snippets demonstrate how to: - Configure the Imagen model with options like image count, aspect ratio, and safety settings. - Generate an image from a text prompt. Region-Tags: - `android_imagen_model_configuration` - `android_imagen_generate_images`
This commit introduces snippets for Imagen 4.0, a text-to-image generation model. It adds new files, `ImagenSnippets.kt` and `ImagenSnippetsJava.java`, which demonstrate how to configure the model and generate images from a text prompt. The commit also includes the following changes: - Adds the `@PublicPreviewAPI` annotation to the new Imagen snippets. - Refactors existing Gemini snippets to initialize models within a static block for consistency. - Adds `@SuppressWarnings("unused")` to several functions and classes to handle linter warnings. - Updates the `build.gradle.kts` file to exclude the `.idea` directory from Spotless XML formatting.
c921479
to
e25629f
Compare
object Gemini25FlashImagePreviewModelConfiguration { | ||
// [START android_gemini_developer_api_gemini_25_flash_image_model] | ||
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel( | ||
modelName = "gemini-2.5-flash-image-preview", |
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.
Is there a way to use dev site variables in our snippets?
I want us to try to move away from hardcoding the model names in our DAC code blocks.
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.
Same question. :) Further to this point, we're sharing values with other teams. Can we just add those variables in here or will that cause questionable results?
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.
The documentation does not currently use variables. If you want to turn those into variables, we could make a separate standalone hard-coded snippet in the documentation that uses the documentation tool variables, but we cannot use the same variables in GitHub. We could then modify the GitHub code to use the same variable name, and define the variable somewhere outside of the snippet region tags.
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.
@sanbeiji do you have any additional feedback on this? Since there aren't any equivalent documentation variables to consider right now, perhaps we can address that later if those variables are created?
This commit introduces a collection of code snippets demonstrating the usage of the Gemini Developer API. It includes examples for model configuration, text-only and multimodal inputs (image, audio, video), multi-turn chat, and image generation/editing.
The necessary dependencies for Firebase AI, Guava, and Reactive Streams have been added to gradle/libs.versions.toml and misc/build.gradle.kts.
Intended documentation pages: