File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
packages/firebase_vertexai/firebase_vertexai Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 1313// limitations under the License.
1414
1515import 'package:firebase_core/firebase_core.dart' ;
16+ import 'package:firebase_auth/firebase_auth.dart' ;
1617import 'package:firebase_vertexai/firebase_vertexai.dart' ;
1718import 'package:flutter/material.dart' ;
1819import 'package:flutter/services.dart' ;
@@ -90,10 +91,12 @@ class _ChatWidgetState extends State<ChatWidget> {
9091 super .initState ();
9192
9293 initFirebase ().then ((value) {
93- _model = FirebaseVertexAI .instance.generativeModel (
94+ var vertex_instance =
95+ FirebaseVertexAI .instanceFor (auth: FirebaseAuth .instance);
96+ _model = vertex_instance.generativeModel (
9497 model: 'gemini-1.5-flash' ,
9598 );
96- _functionCallModel = FirebaseVertexAI .instance .generativeModel (
99+ _functionCallModel = vertex_instance .generativeModel (
97100 model: 'gemini-1.5-flash' ,
98101 tools: [
99102 Tool .functionDeclarations ([fetchWeatherTool]),
@@ -156,6 +159,7 @@ class _ChatWidgetState extends State<ChatWidget> {
156159 Future <void > initFirebase () async {
157160 // ignore: avoid_redundant_argument_values
158161 await Firebase .initializeApp (options: options);
162+ await FirebaseAuth .instance.signInAnonymously ();
159163 }
160164
161165 void _scrollDown () {
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ final class GenerativeModel {
159159 if (auth != null ) {
160160 final idToken = await auth.currentUser? .getIdToken ();
161161 if (idToken != null ) {
162- headers['Authorization' ] = idToken;
162+ headers['Authorization' ] = 'Firebase $ idToken ' ;
163163 }
164164 }
165165 return headers;
You can’t perform that action at this time.
0 commit comments