@@ -42,36 +42,35 @@ from the `google_generative_ai` and `firebase_vertexai` packages to the new
42
42
` firebase_ai ` package.
43
43
44
44
One change is that there is now a single ` FirebaseProvider ` that works for both
45
- Gemini and Vertex. Both of these providers served up the same models in the
46
- past, e.g. ` gemini-2.0-flash ` , but did so via different mechanisms; one was via
47
- an API key and the other was via a Firebase project. The other real difference
48
- was the billing model. When using the ` firebase_ai ` package, API key support has
49
- been dropped in favor of always requiring a Firebase project. The only remaining
50
- difference is the billing model, which [ you can read about in the Firebase
51
- docs] ( https://firebase.google.com/docs/ai-logic/get-started?platform=flutter&api=dev#set-up-firebase ) .
45
+ Gemini and Vertex. Both of these providers served the same models in the past,
46
+ e.g. ` gemini-2.0-flash ` , but did so via different mechanisms: one used an API
47
+ key and the other used a Firebase project. Another difference is the billing
48
+ model. When using the ` firebase_ai ` package, API key support has been dropped in
49
+ favor of always requiring a Firebase project. You can read about billing in the
50
+ Firebase docs: https://firebase.google.com/docs/ai-logic/get-started?platform=flutter&api=dev#set-up-firebase
52
51
53
- To migrate, the following code using the ` GeminiProvider ` :
52
+ To migrate, the following code that uses the ` GeminiProvider ` :
54
53
55
54
``` dart
56
- class ChatPage extends StatelessWidget {
57
- const ChatPage({super.key, required this.title});
58
- final String title;
55
+ class ChatPage extends StatelessWidget {
56
+ const ChatPage({super.key, required this.title});
57
+ final String title;
59
58
60
- @override
61
- Widget build(BuildContext context) {
62
- return Scaffold(
63
- appBar: AppBar(title: Text(title)),
64
- body: LlmChatView(
65
- provider: GeminiProvider( // this changes
66
- model: GenerativeModel( // and this changes
67
- model: 'gemini-2.0-flash',
68
- apiKey: 'GEMINI-API-KEY', // and this changes
69
- ),
70
- ),
59
+ @override
60
+ Widget build(BuildContext context) {
61
+ return Scaffold(
62
+ appBar: AppBar(title: Text(title)),
63
+ body: LlmChatView(
64
+ provider: GeminiProvider( // this changes
65
+ model: GenerativeModel( // and this changes
66
+ model: 'gemini-2.0-flash',
67
+ apiKey: 'GEMINI-API-KEY', // and this changes
71
68
),
72
- );
73
- }
74
- }
69
+ ),
70
+ ),
71
+ );
72
+ }
73
+ }
75
74
```
76
75
77
76
now becomes code that uses ` googleAI() ` :
@@ -92,25 +91,26 @@ class ChatPage extends StatelessWidget {
92
91
}
93
92
```
94
93
95
- And the following code using the ` VertexProvider ` :
94
+ And the following code that uses the ` VertexProvider ` :
96
95
97
96
``` dart
98
97
class ChatPage extends StatelessWidget {
99
98
const ChatPage({super.key});
100
99
101
100
@override
102
101
Widget build(BuildContext context) => Scaffold(
103
- appBar: AppBar(title: const Text(App.title)),
104
- body: LlmChatView(
105
- provider: VertexProvider( // this changes
106
- chatModel: FirebaseVertexAI.instance.generativeModel( // and this
107
- model: 'gemini-2.0-flash',
108
- ),
109
- ),
102
+ appBar: AppBar(title: const Text(App.title)),
103
+ body: LlmChatView(
104
+ provider: VertexProvider( // this changes
105
+ chatModel: FirebaseVertexAI.instance.generativeModel( // and this
106
+ model: 'gemini-2.0-flash',
110
107
),
111
- );
108
+ ),
109
+ ),
110
+ );
112
111
}
113
112
```
113
+
114
114
becomes code that uses ` vertexAI() ` :
115
115
116
116
``` dart
@@ -177,8 +177,7 @@ void main() async {
177
177
2. ** Configuration**
178
178
179
179
To use Firebase AI in your project, follow the steps described in [Get
180
- started with the Gemini API using the Firebase AI Logic SDKs
181
- ](https://firebase.google.com/docs/ai-logic/get-started? api=dev).
180
+ started with the Gemini API using the Firebase AI Logic SDKs](https://firebase.google.com/docs/ai-logic/get-started? api=dev).
182
181
183
182
After following these instructions, you' re ready to use Firebase AI in your
184
183
Flutter app. Start by initializing Firebase:
@@ -210,15 +209,15 @@ void main() async {
210
209
211
210
@override
212
211
Widget build(BuildContext context) => Scaffold(
213
- appBar: AppBar(title: const Text(App.title)),
214
- body: LlmChatView(
215
- provider: FirebaseProvider(
216
- model: FirebaseAI.vertexAI ().generativeModel(
217
- model: ' gemini-2.0-flash'
218
- ),
219
- ),
212
+ appBar: AppBar(title: const Text(App.title)),
213
+ body: LlmChatView(
214
+ provider: FirebaseProvider(
215
+ model: FirebaseAI.vertexAI ().generativeModel(
216
+ model: ' gemini-2.0-flash'
220
217
),
221
- );
218
+ ),
219
+ ),
220
+ );
222
221
}
223
222
` ` `
224
223
@@ -265,8 +264,8 @@ To enable network access on Android, ensure that your `AndroidManifest.xml` file
265
264
- ** File selection:**
266
265
To enable users to select and attach files,
267
266
follow the [usage instructions][file-setup] for ` package:file_selector` .
268
- - ** Image selection:**
269
267
268
+ - ** Image selection:**
270
269
To enable users to take or select a picture from their device, refer to
271
270
the [installation instructions][image-setup] for ` package:image_picker` .
272
271
@@ -280,7 +279,7 @@ To enable network access on Android, ensure that your `AndroidManifest.xml` file
280
279
# # Samples
281
280
282
281
To run the [example apps][] in the ` example/lib` directory, first replace the
283
- ` example/lib/firebase_options.dart` file by running ` flutterfire config` (you
282
+ ` example/lib/firebase_options.dart` file by running ` flutterfire config` (you
284
283
may need to manually delete this file first). The provided
285
284
` firebase_options.dart` file is a placeholder for configuration needed by the
286
285
examples.
0 commit comments