Skip to content

Commit 9f69309

Browse files
authored
fix(vertexai): hotfix for vertexai auth access to storage (#13534)
* hotfix for vertexai auth access to storage * remove unused change
1 parent 3480ce7 commit 9f69309

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/firebase_vertexai/firebase_vertexai/example/lib/main.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import 'package:firebase_core/firebase_core.dart';
16+
import 'package:firebase_auth/firebase_auth.dart';
1617
import 'package:firebase_vertexai/firebase_vertexai.dart';
1718
import 'package:flutter/material.dart';
1819
import '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() {

packages/firebase_vertexai/firebase_vertexai/lib/src/model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)