Skip to content

Davidmotson.firebase ai #6911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ jobs:
distribution: temurin
cache: gradle

- name: Clone mock responses
- name: Clone vertexai mock responses
if: matrix.module == ':firebase-vertexai'
run: firebase-vertexai/update_responses.sh

- name: Clone ai mock responses
if: matrix.module == ':firebase-ai'
run: firebase-ai/update_responses.sh

- name: Add google-services.json
env:
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
Expand Down
15 changes: 15 additions & 0 deletions firebase-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Unreleased
* [changed] **Breaking Change**: `LiveModelFutures.connect` now returns `ListenableFuture<LiveSessionFutures>` instead of `ListenableFuture<LiveSession>`.
* **Action Required:** Remove any transformations from LiveSession object to LiveSessionFutures object.
* **Action Required:** Change type of variable handling `LiveModelFutures.connect` to `ListenableFuture<LiveSessionsFutures>`
* [changed] **Breaking Change**: Removed `UNSPECIFIED` value for enum class `ResponseModality`
* **Action Required:** Remove all references to `ResponseModality.UNSPECIFIED`
* [changed] **Breaking Change**: Renamed `LiveGenerationConfig.setResponseModalities` to `LiveGenerationConfig.setResponseModality`
* **Action Required:** Replace all references of `LiveGenerationConfig.setResponseModalities` with `LiveGenerationConfig.setResponseModality`
* [feature] Added support for `HarmBlockThreshold.OFF`. See the
[model documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters#how_to_configure_content_filters){: .external}
for more information.
* [fixed] Improved thread usage when using a `LiveGenerativeModel`. (#6870)
* [fixed] Fixed an issue with `LiveContentResponse` audio data not being present when the model was
interrupted or the turn completed. (#6870)
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)
32 changes: 32 additions & 0 deletions firebase-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Firebase AI SDK

For developer documentation, please visit https://firebase.google.com/docs/vertex-ai.
This README is for contributors building and running tests for the SDK.

## Building

All Gradle commands should be run from the root of this repository.

`./gradlew :firebase-ai:publishToMavenLocal`

## Running Tests

> [!IMPORTANT]
> These unit tests require mock response files, which can be downloaded by running
`./firebase-ai/update_responses.sh` from the root of this repository.

Unit tests:

`./gradlew :firebase-ai:check`

Integration tests, requiring a running and connected device (emulator or real):

`./gradlew :firebase-ai:deviceCheck`

## Code Formatting

Format Kotlin code in this SDK in Android Studio using
the [spotless plugin]([https://plugins.jetbrains.com/plugin/14912-ktfmt](https://github.com/diffplug/spotless)
by running:

`./gradlew firebase-ai:spotlessApply`
908 changes: 908 additions & 0 deletions firebase-ai/api.txt

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions firebase-ai/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class com.google.firebase.ai.type.** { *; }
-keep class com.google.firebase.ai.common.** { *; }
129 changes: 129 additions & 0 deletions firebase-ai/firebase-ai.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("firebase-library")
id("kotlin-android")
alias(libs.plugins.kotlinx.serialization)
}

firebaseLibrary {
testLab.enabled = false
publishJavadoc = true
releaseNotes {
name.set("{{firebase_ai}}")
versionName.set("ai")
hasKTX.set(false)
}
}

android {
val targetSdkVersion: Int by rootProject

namespace = "com.google.firebase.ai"
compileSdk = 34
defaultConfig {
minSdk = 21
consumerProguardFiles("consumer-rules.pro")
multiDexEnabled = true
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions { jvmTarget = "1.8" }
testOptions {
targetSdk = targetSdkVersion
unitTests {
isIncludeAndroidResources = true
isReturnDefaultValues = true
}
}
lint {
targetSdk = targetSdkVersion
baseline = file("lint-baseline.xml")
}
sourceSets { getByName("test").java.srcDirs("src/testUtil") }
}

// Enable Kotlin "Explicit API Mode". This causes the Kotlin compiler to fail if any
// classes, methods, or properties have implicit `public` visibility. This check helps
// avoid accidentally leaking elements into the public API, requiring that any public
// element be explicitly declared as `public`.
// https://github.com/Kotlin/KEEP/blob/master/proposals/explicit-api-mode.md
// https://chao2zhang.medium.com/explicit-api-mode-for-kotlin-on-android-b8264fdd76d1
tasks.withType<KotlinCompile>().all {
if (!name.contains("test", ignoreCase = true)) {
if (!kotlinOptions.freeCompilerArgs.contains("-Xexplicit-api=strict")) {
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
}
}
}

dependencies {
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.websockets)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.logging)

api("com.google.firebase:firebase-common:21.0.0")
implementation("com.google.firebase:firebase-components:18.0.0")
implementation("com.google.firebase:firebase-annotations:16.2.0")
implementation("com.google.firebase:firebase-appcheck-interop:17.1.0")
implementation(libs.androidx.annotation)
implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.core.ktx)
implementation(libs.slf4j.nop)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.reactive)
implementation(libs.reactive.streams)
implementation("com.google.guava:listenablefuture:1.0")
implementation("androidx.concurrent:concurrent-futures:1.2.0")
implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0")
implementation("com.google.firebase:firebase-auth-interop:18.0.0")

testImplementation(libs.kotest.assertions.core)
testImplementation(libs.kotest.assertions)
testImplementation(libs.kotest.assertions.json)
testImplementation(libs.ktor.client.okhttp)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.org.json)
testImplementation(libs.androidx.test.junit)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.junit)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.robolectric)
testImplementation(libs.truth)
testImplementation(libs.mockito.core)

androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.truth)
}
16 changes: 16 additions & 0 deletions firebase-ai/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=16.0.0
latestReleasedVersion=
20 changes: 20 additions & 0 deletions firebase-ai/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<issues format="6" by="lint 8.3.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.3.2)" variant="all" version="8.3.2">


</issues>
21 changes: 21 additions & 0 deletions firebase-ai/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
35 changes: 35 additions & 0 deletions firebase-ai/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 Google LLC -->
<!-- -->
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
<!-- you may not use this file except in compliance with the License. -->
<!-- You may obtain a copy of the License at -->
<!-- -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
<!--<uses-sdk android:minSdkVersion="21"/>-->

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- To use the audio conversation feature of Live Sessions, update your app's manifest -->
<!-- to request audio recording permission -->
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->

<application>
<service android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.ai.FirebaseAIRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
Loading
Loading