Skip to content

Commit 8ff653e

Browse files
authored
feat(firebaseai): Added support for Server Prompt Template (#17767)
* init setup * add the api * Add chat page test case * add template imagen generate * add history placeholder * more examples for server template * create new models for template request * working example with new architecture * some tweak to clean up the PR * Update server prompt api name and generateContentStream * name updates and stream for chat history * tweak UI a bit * add media sample * add function calling test * testing imagen * make inputs optional * Add documentations * add test and function calling * make inputs required * remove chat feature * some gemini comments * add documentations * fix the template test * fix pr comments * update the test internal constructor and add more annotations
1 parent dac0b0b commit 8ff653e

File tree

12 files changed

+998
-67
lines changed

12 files changed

+998
-67
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import 'pages/json_schema_page.dart';
3131
import 'pages/schema_page.dart';
3232
import 'pages/token_count_page.dart';
3333
import 'pages/video_page.dart';
34+
import 'pages/server_template_page.dart';
3435

3536
void main() async {
3637
WidgetsFlutterBinding.ensureInitialized();
@@ -199,6 +200,11 @@ class _HomeScreenState extends State<HomeScreen> {
199200
model: currentModel,
200201
useVertexBackend: useVertexBackend,
201202
);
203+
case 11:
204+
return ServerTemplatePage(
205+
title: 'Server Template',
206+
useVertexBackend: useVertexBackend,
207+
);
202208

203209
default:
204210
// Fallback to the first page in case of an unexpected index
@@ -227,18 +233,15 @@ class _HomeScreenState extends State<HomeScreen> {
227233
style: TextStyle(
228234
fontSize: 12,
229235
color: widget.useVertexBackend
230-
? Theme.of(context)
231-
.colorScheme
232-
.onSurface
233-
.withValues(alpha: 0.7)
236+
? Theme.of(context).colorScheme.onSurface.withAlpha(180)
234237
: Theme.of(context).colorScheme.primary,
235238
),
236239
),
237240
Switch(
238241
value: widget.useVertexBackend,
239242
onChanged: widget.onBackendChanged,
240-
activeTrackColor: Colors.green.withValues(alpha: 0.5),
241-
inactiveTrackColor: Colors.blueGrey.withValues(alpha: 0.5),
243+
activeTrackColor: Colors.green.withAlpha(128),
244+
inactiveTrackColor: Colors.blueGrey.withAlpha(128),
242245
activeThumbColor: Colors.green,
243246
inactiveThumbColor: Colors.blueGrey,
244247
),
@@ -251,7 +254,7 @@ class _HomeScreenState extends State<HomeScreen> {
251254
: Theme.of(context)
252255
.colorScheme
253256
.onSurface
254-
.withValues(alpha: 0.7),
257+
.withAlpha(180),
255258
),
256259
),
257260
],
@@ -273,7 +276,7 @@ class _HomeScreenState extends State<HomeScreen> {
273276
unselectedFontSize: 9,
274277
selectedItemColor: Theme.of(context).colorScheme.primary,
275278
unselectedItemColor: widget.useVertexBackend
276-
? Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7)
279+
? Theme.of(context).colorScheme.onSurface.withAlpha(180)
277280
: Colors.grey,
278281
items: const <BottomNavigationBarItem>[
279282
BottomNavigationBarItem(
@@ -333,6 +336,13 @@ class _HomeScreenState extends State<HomeScreen> {
333336
label: 'Live',
334337
tooltip: 'Live Stream',
335338
),
339+
BottomNavigationBarItem(
340+
icon: Icon(
341+
Icons.storage,
342+
),
343+
label: 'Server',
344+
tooltip: 'Server Template',
345+
),
336346
],
337347
currentIndex: widget.selectedIndex,
338348
onTap: _onItemTapped,

packages/firebase_ai/firebase_ai/example/lib/pages/image_prompt_page.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
1514
import 'package:flutter/material.dart';
1615
import 'package:firebase_ai/firebase_ai.dart';
1716
import 'package:flutter/services.dart';
@@ -65,11 +64,13 @@ class _ImagePromptPageState extends State<ImagePromptPage> {
6564
var content = _generatedContent[idx];
6665
return MessageWidget(
6766
text: content.text,
68-
image: Image.memory(
69-
content.imageBytes!,
70-
cacheWidth: 400,
71-
cacheHeight: 400,
72-
),
67+
image: content.imageBytes == null
68+
? null
69+
: Image.memory(
70+
content.imageBytes!,
71+
cacheWidth: 400,
72+
cacheHeight: 400,
73+
),
7374
isFromUser: content.fromUser ?? false,
7475
);
7576
},

0 commit comments

Comments
 (0)