Skip to content

Commit 69aa3c3

Browse files
authored
refactor(ai-logic): split samples into various ViewModels (#2767)
The goal is to make these samples more readable by splitting them into various ViewModels - each sample/feature has its own ViewModel. There should be no UI change (other than typo fixes) or functionality changes.
1 parent 70b702e commit 69aa3c3

45 files changed

Lines changed: 1850 additions & 1235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

firebase-ai/README.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,68 @@
22

33
This Android sample app demonstrates how to use state-of-the-art
44
generative AI models (like Gemini) to build AI-powered features and applications.
5+
56
For more information about Firebase AI Logic, visit the [documentation](http://firebase.google.com/docs/ai-logic).
67

8+
## Setup & Configuration
9+
10+
### Prerequisites
11+
* **Google AI (Gemini) API Key**: Most samples work out of the box with the Google AI SDK.
12+
* **Vertex AI**: Samples marked with *(Vertex AI)* require you to enable the Vertex AI API in your Google Cloud project and have your files in Cloud Storage.
13+
* **Server Prompt Templates**: These samples require you to set up templates in the [Firebase Console](https://console.firebase.google.com/project/_/ai-logic).
14+
715
## Getting Started
816

917
To try out this sample app, you need to use latest stable version of Android Studio.
10-
However, if you want to latest lint checks and AI productivity features in Android
11-
Studio use the latest preview version of [Android Studio](https://developer.android.com/studio/preview).
18+
19+
* [Set up your Android app for Firebase][setup-android]
20+
* Use the package name `com.google.firebase.quickstart.ai`
21+
* [Set up Firebase AI Logic][setup-ai-logic]
22+
* Run the app on an Android device or emulator.
1223

1324
## Features
1425

15-
There are 2 main files that demonstrate the use of Firebase AI Logic:
16-
17-
- [ChatViewModel.kt](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ChatViewModel.kt)
18-
which can do things such as:
19-
- [Generate Text](https://firebase.google.com/docs/ai-logic/generate-text)
20-
- [Generate structured output (JSON)](https://firebase.google.com/docs/ai-logic/generate-structured-output)
21-
- [Analyze images](https://firebase.google.com/docs/ai-logic/analyze-images)
22-
- [Analyze video](https://firebase.google.com/docs/ai-logic/analyze-video)
23-
- [Analyze audio](https://firebase.google.com/docs/ai-logic/analyze-audio)
24-
- [Analyze documents (PDFs)](https://firebase.google.com/docs/ai-logic/analyze-documents)
25-
- [Generate images using Gemini 2.0](https://firebase.google.com/docs/ai-logic/generate-images-imagen)
26-
- [Function calling](https://firebase.google.com/docs/ai-logic/function-calling)
27-
- [ImagenViewModel](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenViewModel.kt)
28-
which shows how to [Generate images using Imagen models](https://firebase.google.com/docs/ai-logic/generate-images-imagen)
26+
You can find the implementation for each feature by clicking on the links below:
27+
28+
### Text / Chat
29+
- [Travel tips](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/TravelTipsViewModel.kt): The user wants the model to help a new traveler with travel tips
30+
- [Chatbot recommendations for courses](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/CourseRecommendationsViewModel.kt): A chatbot suggests courses for a performing arts program.
31+
- [Weather Chat](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/WeatherChatViewModel.kt): Use function calling to get the weather conditions for a specific US city on a specific date.
32+
- [Grounding with Google Search](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/GoogleSearchGroundingViewModel.kt): Use Grounding with Google Search to get responses based on up-to-date information from the web.
33+
- [Thinking](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ThinkingChatViewModel.kt): Gemini 2.5 Flash with dynamic thinking
34+
- [Server Prompt Templates - Gemini](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ServerPromptTemplateViewModel.kt): Generate an invoice using server prompt templates.
35+
36+
### Image analysis / generation
37+
- [Imagen 4 - image generation](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenGenerationViewModel.kt): Generate images using Imagen 4
38+
- [Imagen 3 - Inpainting (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenInpaintingViewModel.kt): Replace part of an image using Imagen 3
39+
- [Imagen 3 - Outpainting (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenOutpaintingViewModel.kt): Expand an image by drawing in more background
40+
- [Imagen 3 - Subject Reference (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenSubjectReferenceViewModel.kt): Generate an image using a referenced subject (must be an animal)
41+
- [Imagen 3 - Style Transfer (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenStyleTransferViewModel.kt): Change the art style of a cat picture using a reference
42+
- [Gemini 2.5 Flash Image (aka nanobanana)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageGenerationViewModel.kt): Generate and/or edit images using Gemini 2.5 Flash Image aka nanobanana
43+
- [Server Prompt Template - Imagen](app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenTemplateViewModel.kt): Generate an image using a server prompt template.
44+
- [SVG Generator](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/SvgViewModel.kt): Use Gemini 3 Flash preview to create SVG illustrations
45+
- [Blog post creator (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ImageBlogCreatorViewModel.kt): Create a blog post from an image file stored in Cloud Storage.
46+
47+
### Audio analysis
48+
- [Audio Summarization](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioSummarizationViewModel.kt): Summarize an audio file
49+
- [Translation from audio (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/AudioTranslationViewModel.kt): Translate an audio file stored in Cloud Storage
50+
51+
### Video analysis
52+
- [Hashtags for a video (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoHashtagGeneratorViewModel.kt): Generate hashtags for a video ad stored in Cloud Storage
53+
- [Summarize video](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/VideoSummarizationViewModel.kt): Summarize a video and extract important dialogue.
54+
55+
### Live API (Real-time bidrectional streaming)
56+
- [ForecastTalk](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamAudioViewModel.kt): Use bidirectional streaming to get information about weather conditions
57+
- [Gemini Live (Video input)](app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamVideoViewModel.kt): Use bidirectional streaming to chat with Gemini using your phone's camera
58+
59+
### Document (PDFs) analysis
60+
- [Document comparison (Vertex AI)](app/src/main/java/com/google/firebase/quickstart/ai/feature/text/DocumentComparisonViewModel.kt): Compare the contents of 2 documents in Cloud Storage.
61+
2962

3063
## All samples
3164

3265
The full list of available samples can be found in the
33-
[FirebaseAISamples.kt file](app/src/main/java/com/google/firebase/quickstart/ai/FirebaseAISamples.kt).
66+
[FirebaseAISamples.kt file](app/src/main/java/com/google/firebase/quickstart/ai/ui/navigation/FirebaseAISamples.kt).
67+
68+
[setup-android]: https://firebase.google.com/docs/android/setup
69+
[setup-ai-logic]: https://firebase.google.com/docs/ai-logic/get-started?api=dev#set-up-firebase

0 commit comments

Comments
 (0)