Skip to content

Commit cfadef3

Browse files
authored
Merge pull request #10 from HYACCCINT/main
"Planning with the Gemini API" - a Firebase AI sample app
2 parents 7a7a380 + 3b7b317 commit cfadef3

33 files changed

Lines changed: 813 additions & 858 deletions

README.md

Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
1-
# Make It So
1+
# "Planning with the Gemini API" - a Firebase AI sample app
22

3-
Welcome to the _Make It So_ sample app, an AI-powered web app for to-do lists!
4-
It's an [Angular](https://angular.io/) app built using the Gemini API and Firebase.
3+
Welcome to the _Planning with the Gemini API_ sample app, an AI-powered web app
4+
for to-do lists! It's an [Angular](https://angular.io/) app built using the
5+
Gemini API and Firebase.
56

67
The [Gemini API](https://ai.google.dev/gemini-api) gives you access to Google's latest
7-
generative AI models – the Gemini family of multimodal models. This _Make It So_ web app
8-
calls the Gemini API to generate a task list from either text or an image provided by
9-
the end user.
8+
generative AI models – the Gemini family of multimodal models.
9+
This _Planning with the Gemini API_ web app calls the Gemini API to generate a task list
10+
from either text or an image provided by the end user.
1011

11-
The backend of _Make It So_ is powered by [Firebase](https://firebase.google.com/),
12-
which is Google's platform for building fullstack multi-platform apps. This app uses
12+
The backend of _Planning with the Gemini API_ is powered by
13+
[Firebase](https://firebase.google.com/), which is Google's platform for
14+
building fullstack multi-platform apps. This app uses
1315
[Firebase Authentication](https://firebase.google.com/products/auth) for signing-in
1416
and authorizing end users. It also uses
1517
[Firestore](https://firebase.google.com/products/firestore) – a NoSQL realtime database –
1618
to store the to-do list items.
1719

18-
> [!CAUTION]
19-
> **In its default state, this sample app is for _experimentation and prototyping only_.**
20+
> [!CAUTION] > **In its DEFAULT state, this sample app is for _EXPERIMENTATION and PROTOTYPING ONLY_.**
2021
> It uses the [Google AI SDK for JavaScript](https://ai.google.dev/gemini-api/docs/quickstart?lang=web)
2122
> directly from the client-side which means that you risk potentially exposing your
2223
> Gemini API key to malicious actors if you deploy this app.
23-
>
24+
>
2425
> If you want to deploy this sample app or use it as a base for a production app,
2526
> **we strongly recommend that you
2627
> [migrate to use the Vertex AI in Firebase SDK](https://github.com/FirebaseExtended/make-it-so-angular/main/README.md#migrate-to-use-vertex-ai-in-firebase),
2728
> which offers security options against unauthorized clients.**
2829
2930
## Explore the app's codebase
3031

31-
* In `src/environments/environments.ts`, you can find important configuration values:
32+
- In `src/environments/environments.ts`, you can find important configuration values:
3233

33-
* Within `firebase`, find the values needed to connect your app to Firebase
34+
- Within `firebase`, find the values needed to connect your app to Firebase
3435
(most importantly `apiKey`, `projectId`, and `appId`).
35-
* Find your Gemini API key (`gemini_api_key`).
36+
- Find your Gemini API key (`gemini_api_key`).
3637

3738
Note that if you
3839
[run the sample app in IDX](https://github.com/FirebaseExtended/make-it-so-angular/main/README.md#set-up-and-run-the-app),
3940
then these config values will be automatically populated into the file for you.
4041

41-
* In `src/app/services/task.service.ts`, you can explore how to make a basic call to
42+
- In `src/app/services/task.service.ts`, you can explore how to make a basic call to
4243
the Gemini API, including:
4344

44-
* Importing the Google AI package: `google/generative-ai`.
45-
* Initializing the Google AI service and the generative model.
46-
* Calling `generateContent` to send the request to Gemini with the provided prompt
45+
- Importing the Google AI package: `google/generative-ai`.
46+
- Initializing the Google AI service and the generative model.
47+
- Calling `generateContent` to send the request to Gemini with the provided prompt
4748
(and image, if provided).
4849

49-
* In `src/app/app.config.ts` and `src/app/services/task.service.ts`, you can explore
50+
- In `src/app/app.config.ts` and `src/app/services/task.service.ts`, you can explore
5051
how to use Firebase, including:
5152

52-
* Using Firebase Authentication's
53+
- Using Firebase Authentication's
5354
[anonymous authentication method](https://firebase.google.com/docs/auth/web/anonymous-auth)
5455
to create an authenticated user account.
55-
* Using Firestore to write and read to-do tasks and subtasks generated by Gemini.
56+
- Using Firestore to write and read to-do tasks and subtasks generated by Gemini.
5657

5758
## Set up and run the app
5859

5960
You can either run the sample app in IDX (recommended) or locally.
6061

6162
### Option 1: Run in IDX _(recommended)_
6263

63-
This _Make It So_ web app is best experienced by running it in [IDX](https://idx.dev/),
64-
which is Google's browser-based workspace for building, shipping, and managing
65-
full-stack multiplatform apps.
64+
This _Planning with the Gemini API_ web app is best experienced by running it in
65+
[IDX](https://idx.dev/), which is Google's browser-based workspace for
66+
building, shipping, and managing full-stack multiplatform apps.
6667

6768
Firebase provides a custom workflow using IDX to help you quickly experiment with the sample app.
6869
This workflow automatically sets up a new Firebase project with Authentication and Firestore
@@ -75,61 +76,62 @@ You can also kick-off this custom workflow from the Firebase console in the
7576
_Build with Gemini_ section (find the "Experiment with a Gemini sample app" banner).
7677

7778
Here's some additional information about this custom workflow:
78-
* To somewhat protect your Gemini API key, the workflow has imposed a quota limit on the
79+
80+
- To somewhat protect your Gemini API key, the workflow has imposed a quota limit on the
7981
API key of 10 RPM.
80-
* This workflow creates a new IDX workspace. If you run out of workspace quota, go to
82+
- This workflow creates a new IDX workspace. If you run out of workspace quota, go to
8183
[idx.google.com](idx.google.com) to delete an old workspace.
8284

8385
### Option 2: Run locally
8486

85-
You can also run this _Make It So_ web app locally. You'll just need to complete some
86-
manual setup steps.
87+
You can also run this _Planning with the Gemini API_ web app locally. You'll just need
88+
to complete some manual setup steps.
8789

8890
#### Prerequisites
8991

90-
* Node.js v20+
91-
* npm v10+
92-
* Angular CLI 18+
92+
- Node.js v20+
93+
- npm v10+
94+
- Angular CLI 18+
9395

9496
#### Setup instructions
9597

9698
1. Set up Firebase:
97-
1. Create a new Firebase project in the
98-
[Firebase console](https://console.firebase.google.com/).
99-
You can skip setting up Google Analytics.
100-
1. Enable [Firestore](https://console.firebase.google.com/u/0/project/_/firestore)
101-
and [anonymous authentication](https://console.firebase.google.com/u/0/project/_/authentication)
102-
in your new project.
103-
1. Create a new Firebase web app in your new project.
104-
You can skip setting up Firebase Hosting.
105-
1. Copy your Firebase config object, and replace the placeholder values in the
106-
`src/environments/environments.ts` file of the sample app.
107-
108-
1. Set up the Gemini API:
109-
1. [Get a Gemini API key](https://aistudio.google.com/app/apikey) in Google AI Studio.
110-
Use the Firebase project you just created.
111-
1. Add your Gemini API key into the `src/environments/environments.ts` file of the sample app.
112-
113-
1. Run `npm install` to install the app's dependencies.
114-
115-
1. Serve the app:
116-
1. Run `ng serve` to start the Angular development server.
117-
1. Open your browser and navigate to `http://localhost:4200`.
99+
a. Create a new Firebase project in the
100+
[Firebase console](https://console.firebase.google.com/).
101+
You can skip setting up Google Analytics.
102+
b. Enable [Firestore](https://console.firebase.google.com/u/0/project/_/firestore)
103+
and [anonymous authentication](https://console.firebase.google.com/u/0/project/_/authentication)
104+
in your new project.
105+
c. Create a new Firebase web app in your new project.
106+
You can skip setting up Firebase Hosting.
107+
d. Copy your Firebase config object, and replace the placeholder values in the
108+
`src/environments/environments.ts` file of the sample app.
109+
110+
2. Set up the Gemini API:
111+
a. [Get a Gemini API key](https://aistudio.google.com/app/apikey) in Google AI Studio.
112+
Use the Firebase project you just created.
113+
b. Add your Gemini API key into the `src/environments/environments.ts` file of the sample app.
114+
115+
3. Run `npm install` to install the app's dependencies.
116+
117+
4. Serve the app:
118+
a. Run `ng serve` to start the Angular development server.
119+
b. Open your browser and navigate to `http://localhost:4200`.
118120

119121
## Interact with the app
120122

121123
1. Create a new task.\
122124
Click the "New task" button on the left to initiate the creation of a new task.
123125
Gemini suggests a task title. Edit the title as desired.
124126

125-
1. Generate subtasks.\
127+
2. Generate subtasks.\
126128
Gemini can generate a list of subtasks based either on your title and/or an uploaded image.
127129

128-
1. Save the task to add it to the dashboard of to-do tasks.
130+
3. Save the task to add it to the dashboard of to-do tasks.
129131

130132
## Migrate to use Vertex AI in Firebase
131133

132-
**In its default state, this sample app is for _experimentation and prototyping only_.**
134+
**In its DEFAULT state, this sample app is for _EXPERIMENTATION and PROTOTYPING ONLY_.**
133135
It uses the [Google AI SDK for JavaScript](https://ai.google.dev/gemini-api/docs/quickstart?lang=web)
134136
directly from the client-side which means that you risk potentially exposing your Gemini API key
135137
to malicious actors if you deploy this app.
@@ -152,31 +154,32 @@ your Firebase project (as described below).
152154
and then click the _Vertex AI in Firebase_ card to launch a workflow that helps you
153155
do the following tasks (if they're not already done):
154156

155-
* Upgrade your project to use the
157+
- Upgrade your project to use the
156158
[pay-as-you-go Blaze pricing plan](https://console.firebase.google.com/project/_/overview?purchaseBillingPlan=metered).
157-
* Enable the following two APIs for your project:\
158-
[aiplatform.googleapis.com](https://console.cloud.google.com/apis/library/aiplatform.googleapis.com?project=_)
159+
- Enable the following two APIs for your project:\
160+
[Vertex AI API](https://console.cloud.google.com/apis/library/aiplatform.googleapis.com?project=_)
159161
and
160-
[firebaseml.googleapis.com](https://console.cloud.google.com/apis/library/firebaseml.googleapis.com?project=_)
162+
[Firebase ML API](https://console.cloud.google.com/apis/library/firebaseml.googleapis.com?project=_)
161163

162-
1. As soon as you start seriously developing your app,
164+
2. As soon as you start seriously developing your app,
163165
[set up Firebase App Check](https://firebase.google.com/docs/vertex-ai/app-check)
164166
to protect your app from abuse by unauthorized clients.
165167

166-
1. Follow security best practices by cleaning up your Firebase project and sample app:
168+
3. Follow security best practices by cleaning up your Firebase project and sample app:
169+
170+
- If you're no longer using your Gemini API key, then delete it.
167171

168-
* If you're no longer using your Gemini API key, then delete it.
169-
* In the [**API keys** section of Google AI Studio](https://aistudio.google.com/app/apikey),
172+
- In the [**API keys** section of Google AI Studio](https://aistudio.google.com/app/apikey),
170173
view and delete your Gemini API key.
171-
* In the sample app's codebase, delete references to the Gemini API key in the following places:
172-
* `google_apikeys_key` resource entry in `main.tf`
173-
* `gemini_api_key` in both `src/environments/environments.ts` and `src/environments/environments.ts.tmpl`
174+
- In the sample app's codebase, delete references to the Gemini API key in the following places:
175+
- `google_apikeys_key` resource entry in `main.tf`
176+
- `gemini_api_key` in both `src/environments/environments.ts` and `src/environments/environments.ts.tmpl`
174177

175-
* If you're no longer using the Google AI Gemini API, then disable it in your project
178+
- If you're no longer using the Google AI Gemini API, then disable it in your project
176179
and delete references to it in your sample app's codebase:
177-
* Disable the API in the Google Cloud console:
180+
- Disable the API in the Google Cloud console:
178181
[generativelanguage.googleapis.com](https://console.cloud.google.com/apis/library/generativelanguage.googleapis.com?project=_)
179-
* Delete references to `generativelanguage.googleapis.com`, including the
182+
- Delete references to `generativelanguage.googleapis.com`, including the
180183
`google_service_usage_consumer_quota_override` resource entry in `main.tf`.
181184

182185
## Troubleshooting
@@ -189,9 +192,9 @@ compute: Received 500
189192
This error happens because authentication has timed-out. Here's how to resolve it:
190193

191194
1. In Project IDX, open a new terminal.
192-
1. In the terminal, run `terraform apply --auto-approve`, and then click continue when prompted to log in.
193-
1. Wait until the command succeeds.
194-
1. Reload the web preview, if necessary.
195+
2. In the terminal, run `terraform apply --auto-approve`, and then click continue when prompted to log in.
196+
3. Wait until the command succeeds.
197+
4. Reload the web preview, if necessary.
195198

196199
```
197200
Error loading Gemini API key. Please rerun Terraform with terraform apply --auto-approve"
@@ -201,27 +204,27 @@ This error happens because Terraform failed to provision some resources
201204
during initialization, such as API keys. Here's how to resolve it:
202205

203206
1. In Project IDX, open a new terminal.
204-
1. In the terminal, run `terraform apply --auto-approve`, and then click
207+
2. In the terminal, run `terraform apply --auto-approve`, and then click
205208
continue when prompted to log in.
206-
1. Wait until the command succeeds.
207-
1. Reload the web preview, if necessary.
209+
3. Wait until the command succeeds.
210+
4. Reload the web preview, if necessary.
208211

209212
```
210213
Check Firestore permissions in Firebase Console: link
211214
```
212215

213216
This error happens because
214217
[Firestore security rules](https://firebase.google.com/docs/firestore/security/get-started)
215-
are blocking requests from your app. Here's how to resolve it:
218+
are blocking requests from your app. Here's how to resolve it:
216219

217220
1. Go to the Firebase console using the link provided in the error message.
218-
1. Check that the security rules are what you expect. In particular,
221+
2. Check that the security rules are what you expect. In particular,
219222
`timestamp.date` should be in the future.
220-
1. Reload the web preview, if necessary.
223+
3. Reload the web preview, if necessary.
221224

222225
## Docs
223226

224-
* [Firebase Support](https://firebase.google.com/support)
225-
* [Google AI Gemini API documentation](https://ai.google.dev/gemini-api/docs/quickstart?lang=web)
227+
- [Firebase Support](https://firebase.google.com/support)
228+
- [Google AI Gemini API documentation](https://ai.google.dev/gemini-api/docs/quickstart?lang=web)
226229
(for experimentation and prototyping)
227-
* [Vertex AI in Firebase documentation](https://firebase.google.com/docs/vertex-ai) (for production apps)
230+
- [Vertex AI in Firebase documentation](https://firebase.google.com/docs/vertex-ai) (for production apps)

firebase.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"hosting": {
3+
"public": "dist/firebase-ai-angular/browser"
4+
}
5+
}

idx-template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "Firebase: Make It So - with AI!",
2+
"name": "Planning with the Gemini API",
33
"description": "A sample web app that demonstrates how to experiment with Firebase and Gemini AI",
44
"categories": [
55
"AI & ML",

0 commit comments

Comments
 (0)