Skip to content

Commit a5e7252

Browse files
authored
disable Live Model when the backend is not vertex ai (#17353)
1 parent dbdd135 commit a5e7252

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

packages/firebase_ai/firebase_ai/example/lib/main.dart

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class HomeScreen extends StatefulWidget {
154154

155155
class _HomeScreenState extends State<HomeScreen> {
156156
void _onItemTapped(int index) {
157+
if (index == 9 && !widget.useVertexBackend) {
158+
// Live Stream feature only works with Vertex AI now.
159+
return;
160+
}
157161
widget.onSelectedIndexChanged(index);
158162
}
159163

@@ -188,7 +192,12 @@ class _HomeScreenState extends State<HomeScreen> {
188192
case 8:
189193
return VideoPage(title: 'Video Prompt', model: currentModel);
190194
case 9:
191-
return BidiPage(title: 'Bidi Stream', model: currentModel);
195+
if (useVertexBackend) {
196+
return BidiPage(title: 'Live Stream', model: currentModel);
197+
} else {
198+
// Fallback to the first page in case of an unexpected index
199+
return ChatPage(title: 'Chat', model: currentModel);
200+
}
192201
default:
193202
// Fallback to the first page in case of an unexpected index
194203
return ChatPage(title: 'Chat', model: currentModel);
@@ -258,58 +267,64 @@ class _HomeScreenState extends State<HomeScreen> {
258267
selectedFontSize: 10,
259268
unselectedFontSize: 9,
260269
selectedItemColor: Theme.of(context).colorScheme.primary,
261-
unselectedItemColor:
262-
Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7),
263-
items: const <BottomNavigationBarItem>[
264-
BottomNavigationBarItem(
270+
unselectedItemColor: widget.useVertexBackend
271+
? Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7)
272+
: Colors.grey,
273+
items: <BottomNavigationBarItem>[
274+
const BottomNavigationBarItem(
265275
icon: Icon(Icons.chat),
266276
label: 'Chat',
267277
tooltip: 'Chat',
268278
),
269-
BottomNavigationBarItem(
279+
const BottomNavigationBarItem(
270280
icon: Icon(Icons.mic),
271281
label: 'Audio',
272282
tooltip: 'Audio Prompt',
273283
),
274-
BottomNavigationBarItem(
284+
const BottomNavigationBarItem(
275285
icon: Icon(Icons.numbers),
276286
label: 'Tokens',
277287
tooltip: 'Token Count',
278288
),
279-
BottomNavigationBarItem(
289+
const BottomNavigationBarItem(
280290
icon: Icon(Icons.functions),
281291
label: 'Functions',
282292
tooltip: 'Function Calling',
283293
),
284-
BottomNavigationBarItem(
294+
const BottomNavigationBarItem(
285295
icon: Icon(Icons.image),
286296
label: 'Image',
287297
tooltip: 'Image Prompt',
288298
),
289-
BottomNavigationBarItem(
299+
const BottomNavigationBarItem(
290300
icon: Icon(Icons.image_search),
291301
label: 'Imagen',
292302
tooltip: 'Imagen Model',
293303
),
294-
BottomNavigationBarItem(
304+
const BottomNavigationBarItem(
295305
icon: Icon(Icons.schema),
296306
label: 'Schema',
297307
tooltip: 'Schema Prompt',
298308
),
299-
BottomNavigationBarItem(
309+
const BottomNavigationBarItem(
300310
icon: Icon(Icons.edit_document),
301311
label: 'Document',
302312
tooltip: 'Document Prompt',
303313
),
304-
BottomNavigationBarItem(
314+
const BottomNavigationBarItem(
305315
icon: Icon(Icons.video_collection),
306316
label: 'Video',
307317
tooltip: 'Video Prompt',
308318
),
309319
BottomNavigationBarItem(
310-
icon: Icon(Icons.stream),
311-
label: 'Bidi',
312-
tooltip: 'Bidi Stream',
320+
icon: Icon(
321+
Icons.stream,
322+
color: widget.useVertexBackend ? null : Colors.grey,
323+
),
324+
label: 'Live',
325+
tooltip: widget.useVertexBackend
326+
? 'Live Stream'
327+
: 'Live Stream (Currently Disabled)',
313328
),
314329
],
315330
currentIndex: widget.selectedIndex,

packages/firebase_ai/firebase_ai/lib/src/firebase_ai.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ class FirebaseAI extends FirebasePluginPlatform {
175175
List<Tool>? tools,
176176
Content? systemInstruction,
177177
}) {
178+
if (!_useVertexBackend) {
179+
throw FirebaseAISdkException(
180+
'LiveGenerativeModel is currently only supported with the VertexAI backend.');
181+
}
178182
return createLiveGenerativeModel(
179183
app: app,
180184
location: location,

0 commit comments

Comments
 (0)