Skip to content

Commit 69cd2a6

Browse files
authored
feat(vertexai): Live API breaking changes (#17299)
* Add a new response api * make vertex android app gradle working * Some more update post release * remove unspecified modality * breaking api update * add todo for server content * fix an error of turncomplete and interrupted null * update to pass analyzer * ignore the documentation
1 parent ec1e6a5 commit 69cd2a6

File tree

13 files changed

+127
-112
lines changed

13 files changed

+127
-112
lines changed

packages/firebase_vertexai/firebase_vertexai/example/android/app/build.gradle

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
plugins {
2+
id "com.android.application"
3+
// START: FlutterFire Configuration
4+
id 'com.google.gms.google-services'
5+
// END: FlutterFire Configuration
6+
id "kotlin-android"
7+
id "dev.flutter.flutter-gradle-plugin"
8+
}
9+
110
def localProperties = new Properties()
211
def localPropertiesFile = rootProject.file('local.properties')
312
if (localPropertiesFile.exists()) {
@@ -6,11 +15,6 @@ if (localPropertiesFile.exists()) {
615
}
716
}
817

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1418
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1519
if (flutterVersionCode == null) {
1620
flutterVersionCode = '1'
@@ -21,20 +25,14 @@ if (flutterVersionName == null) {
2125
flutterVersionName = '1.0'
2226
}
2327

24-
apply plugin: 'com.android.application'
25-
// START: FlutterFire Configuration
26-
apply plugin: 'com.google.gms.google-services'
27-
// END: FlutterFire Configuration
28-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
29-
3028
android {
3129
namespace "com.example.example"
3230

3331
compileSdk 35
3432

3533
defaultConfig {
3634
applicationId "com.example.example"
37-
minSdk 21
35+
minSdk 23
3836
targetSdk 33
3937
versionCode flutterVersionCode.toInteger()
4038
versionName flutterVersionName
@@ -51,6 +49,9 @@ android {
5149
signingConfig signingConfigs.debug
5250
}
5351
}
52+
kotlinOptions {
53+
jvmTarget = '1.8' // Or '11'
54+
}
5455
}
5556

5657
flutter {

packages/firebase_vertexai/firebase_vertexai/example/android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<application
33
android:label="example"
44
android:name="${applicationName}"
5-
android:icon="@mipmap/ic_launcher">
5+
android:icon="@mipmap/ic_launcher"
6+
android:usesCleartextTraffic="true">
67
<activity
78
android:name=".MainActivity"
89
android:exported="true"
@@ -44,4 +45,6 @@
4445
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
4546
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4647
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
48+
<uses-permission android:name="android.permission.INTERNET" />
49+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
4750
</manifest>

packages/firebase_vertexai/firebase_vertexai/example/android/build.gradle

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
buildscript {
2-
repositories {
3-
google()
4-
mavenCentral()
5-
}
6-
7-
dependencies {
8-
classpath 'com.android.tools.build:gradle:8.1.2'
9-
// START: FlutterFire Configuration
10-
classpath 'com.google.gms:google-services:4.4.0'
11-
// END: FlutterFire Configuration
12-
}
13-
}
14-
151
allprojects {
162
repositories {
173
google()

packages/firebase_vertexai/firebase_vertexai/example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip

packages/firebase_vertexai/firebase_vertexai/example/android/settings.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ pluginManagement {
55
def flutterSdkPath = properties.getProperty("flutter.sdk")
66
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
77
return flutterSdkPath
8-
}
9-
settings.ext.flutterSdkPath = flutterSdkPath()
8+
}()
109

11-
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
1211

1312
repositories {
1413
google()

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import 'package:firebase_auth/firebase_auth.dart';
1717
import 'package:firebase_vertexai/firebase_vertexai.dart';
1818
import 'package:flutter/material.dart';
1919

20+
// Import after file is generated through flutterfire_cli.
21+
// import 'package:vertex_ai_example/firebase_options.dart';
22+
2023
import 'pages/chat_page.dart';
2124
import 'pages/audio_page.dart';
2225
import 'pages/function_calling_page.dart';
@@ -28,11 +31,11 @@ import 'pages/document.dart';
2831
import 'pages/video_page.dart';
2932
import 'pages/bidi_page.dart';
3033

31-
// REQUIRED if you want to run on Web
32-
const FirebaseOptions? options = null;
33-
3434
void main() async {
3535
WidgetsFlutterBinding.ensureInitialized();
36+
// Enable this line instead once have the firebase_options.dart generated and
37+
// imported through flutterfire_cli.
38+
// await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
3639
await Firebase.initializeApp();
3740
await FirebaseAuth.instance.signInAnonymously();
3841

packages/firebase_vertexai/firebase_vertexai/example/lib/pages/bidi_page.dart

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class _BidiPageState extends State<BidiPage> {
5959
super.initState();
6060

6161
final config = LiveGenerationConfig(
62-
speechConfig: SpeechConfig(voice: Voice.fenrir),
62+
speechConfig: SpeechConfig(voiceName: 'Fenrir'),
6363
responseModalities: [
6464
ResponseModalities.audio,
6565
],
@@ -328,25 +328,21 @@ class _BidiPageState extends State<BidiPage> {
328328
}
329329
}
330330

331-
Future<void> _handleLiveServerMessage(LiveServerMessage response) async {
332-
if (response is LiveServerContent && response.modelTurn != null) {
333-
await _handleLiveServerContent(response);
334-
}
335-
336-
if (response is LiveServerContent &&
337-
response.turnComplete != null &&
338-
response.turnComplete!) {
339-
await _handleTurnComplete();
340-
}
341-
342-
if (response is LiveServerContent &&
343-
response.interrupted != null &&
344-
response.interrupted!) {
345-
log('Interrupted: $response');
346-
}
331+
Future<void> _handleLiveServerMessage(LiveServerResponse response) async {
332+
final message = response.message;
347333

348-
if (response is LiveServerToolCall && response.functionCalls != null) {
349-
await _handleLiveServerToolCall(response);
334+
if (message is LiveServerContent) {
335+
if (message.modelTurn != null) {
336+
await _handleLiveServerContent(message);
337+
}
338+
if (message.turnComplete != null && message.turnComplete!) {
339+
await _handleTurnComplete();
340+
}
341+
if (message.interrupted != null && message.interrupted!) {
342+
log('Interrupted: $response');
343+
}
344+
} else if (message is LiveServerToolCall && message.functionCalls != null) {
345+
await _handleLiveServerToolCall(message);
350346
}
351347
}
352348

packages/firebase_vertexai/firebase_vertexai/example/lib/utils/audio_recorder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class InMemoryAudioRecorder {
137137
encoder: _encoder,
138138
sampleRate: 16000,
139139
numChannels: 1,
140+
androidConfig: const AndroidRecordConfig(
141+
muteAudio: true,
142+
audioSource: AndroidAudioSource.mic,
143+
),
140144
);
141145
final devs = await _recorder.listInputDevices();
142146
debugPrint(devs.toString());

packages/firebase_vertexai/firebase_vertexai/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ignoresPersistentStateOnLaunch = "NO"
6060
debugDocumentVersioning = "YES"
6161
debugServiceExtension = "internal"
62+
enableGPUValidationMode = "1"
6263
allowLocationSimulation = "YES">
6364
<BuildableProductRunnable
6465
runnableDebuggingMode = "0">

packages/firebase_vertexai/firebase_vertexai/lib/firebase_vertexai.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ export 'src/live_api.dart'
7272
show
7373
LiveGenerationConfig,
7474
SpeechConfig,
75-
Voice,
7675
ResponseModalities,
7776
LiveServerMessage,
7877
LiveServerContent,
7978
LiveServerToolCall,
80-
LiveServerToolCallCancellation;
79+
LiveServerToolCallCancellation,
80+
LiveServerResponse;
8181
export 'src/live_session.dart' show LiveSession;
8282
export 'src/schema.dart' show Schema, SchemaType;

0 commit comments

Comments
 (0)