Skip to content

Commit 274efa9

Browse files
author
David Motsonashvili
committed
fixes for comments
1 parent 1a22821 commit 274efa9

File tree

9 files changed

+38
-20
lines changed

9 files changed

+38
-20
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# Unreleased
2-
3-
2+
* [changed] **Breaking Change**: `LiveModelFutures.connect` now returns `ListenableFuture<LiveSessionFutures>` instead of `ListenableFuture<LiveSession>`.
3+
* **Action Required:** Remove any transformations from LiveSession object to LiveSessionFutures object.
4+
* **Action Required:** Change type of variable handling `LiveModelFutures.connect` to `ListenableFuture<LiveSessionsFutures>`
5+
* [changed] **Breaking Change**: Removed `UNSPECIFIED` value for enum class `ResponseModality`
6+
* **Action Required:** Remove all references to `ResponseModality.UNSPECIFIED`
7+
* [changed] **Breaking Change**: Renamed `LiveGenerationConfig.setResponseModalities` to `LiveGenerationConfig.setResponseModality`
8+
* **Action Required:** Replace all references of `LiveGenerationConfig.setResponseModalities` with `LiveGenerationConfig.setResponseModality`
9+
* [feature] Added support for `HarmBlockThreshold.OFF`. See the
10+
[model documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters#how_to_configure_content_filters){: .external}
11+
for more information.
12+
* [fixed] Improved thread usage when using a `LiveGenerativeModel`. (#6870)
13+
* [fixed] Fixed an issue with `LiveContentResponse` audio data not being present when the model was
14+
interrupted or the turn completed. (#6870)
15+
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)

firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAI.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ import com.google.firebase.ai.type.LiveGenerationConfig
3030
import com.google.firebase.ai.type.PublicPreviewAPI
3131
import com.google.firebase.ai.type.RequestOptions
3232
import com.google.firebase.ai.type.SafetySetting
33+
import com.google.firebase.ai.type.ServiceDisabledException
3334
import com.google.firebase.ai.type.Tool
3435
import com.google.firebase.ai.type.ToolConfig
35-
import com.google.firebase.annotations.concurrent.Background
36+
import com.google.firebase.annotations.concurrent.Blocking
3637
import com.google.firebase.app
3738
import com.google.firebase.appcheck.interop.InteropAppCheckTokenProvider
3839
import com.google.firebase.auth.internal.InternalAuthProvider
3940
import com.google.firebase.inject.Provider
4041
import kotlin.coroutines.CoroutineContext
4142

42-
/** Entry point for all _Vertex AI for Firebase_ functionality. */
43+
/** Entry point for all _Firebase AI_ functionality. */
4344
public class FirebaseAI
4445
internal constructor(
4546
private val firebaseApp: FirebaseApp,
4647
private val backend: GenerativeBackend,
47-
@Background private val backgroundDispatcher: CoroutineContext,
48+
@Blocking private val blockingDispatcher: CoroutineContext,
4849
private val appCheckProvider: Provider<InteropAppCheckTokenProvider>,
4950
private val internalAuthProvider: Provider<InternalAuthProvider>,
5051
) {
52+
init {
53+
validateLocation()
54+
}
5155

5256
/**
5357
* Instantiates a new [GenerativeModel] given the provided parameters.
@@ -72,7 +76,6 @@ internal constructor(
7276
systemInstruction: Content? = null,
7377
requestOptions: RequestOptions = RequestOptions(),
7478
): GenerativeModel {
75-
validateLocation()
7679
val modelUri =
7780
when (backend.backend) {
7881
GenerativeBackendEnum.VERTEX_AI ->
@@ -134,12 +137,16 @@ internal constructor(
134137
.trimIndent(),
135138
)
136139
}
137-
validateLocation()
138140
return LiveGenerativeModel(
139-
"projects/${firebaseApp.options.projectId}/locations/${backend.location}/publishers/google/models/${modelName}",
141+
when (backend.backend) {
142+
GenerativeBackendEnum.VERTEX_AI ->
143+
"projects/${firebaseApp.options.projectId}/locations/${backend.location}/publishers/google/models/${modelName}"
144+
GenerativeBackendEnum.GOOGLE_AI ->
145+
throw ServiceDisabledException("Live Model is not yet available on the Google AI backend")
146+
},
140147
firebaseApp.options.apiKey,
141148
firebaseApp,
142-
backgroundDispatcher,
149+
blockingDispatcher,
143150
generationConfig,
144151
tools,
145152
systemInstruction,
@@ -174,7 +181,6 @@ internal constructor(
174181
GenerativeBackendEnum.GOOGLE_AI ->
175182
"projects/${firebaseApp.options.projectId}/models/${modelName}"
176183
}
177-
validateLocation()
178184
if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) {
179185
Log.w(
180186
TAG,
@@ -223,7 +229,7 @@ internal constructor(
223229
backend: GenerativeBackend
224230
): FirebaseAI {
225231
val multiResourceComponent = app[FirebaseAIMultiResourceComponent::class.java]
226-
return multiResourceComponent.getAI(backend)
232+
return multiResourceComponent.get(backend)
227233
}
228234

229235
/** Returns the [FirebaseAI] instance for the provided [FirebaseApp] */

firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAIMultiResourceComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal class FirebaseAIMultiResourceComponent(
3939

4040
@GuardedBy("this") private val aiInstances: MutableMap<String, FirebaseAI> = mutableMapOf()
4141

42-
fun getAI(backend: GenerativeBackend): FirebaseAI =
42+
fun get(backend: GenerativeBackend): FirebaseAI =
4343
synchronized(this) {
4444
aiInstances[backend.location]
4545
?: FirebaseAI(

firebase-ai/src/main/kotlin/com/google/firebase/ai/FirebaseAIRegistrar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import kotlinx.coroutines.CoroutineDispatcher
3535
* @hide
3636
*/
3737
@Keep
38-
internal class FirebaseVertexAIRegistrar : ComponentRegistrar {
38+
internal class FirebaseAIRegistrar : ComponentRegistrar {
3939
override fun getComponents() =
4040
listOf(
4141
Component.builder(FirebaseAIMultiResourceComponent::class.java)

firebase-ai/src/main/kotlin/com/google/firebase/ai/GenerativeModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ internal constructor(
234234

235235
private fun constructCountTokensRequest(vararg prompt: Content) =
236236
when (generativeBackend.backend) {
237-
GenerativeBackendEnum.GOOGLE_AI -> CountTokensRequest.forGenAI(constructRequest(*prompt))
237+
GenerativeBackendEnum.GOOGLE_AI -> CountTokensRequest.forGoogleAI(constructRequest(*prompt))
238238
GenerativeBackendEnum.VERTEX_AI -> CountTokensRequest.forVertexAI(constructRequest(*prompt))
239239
}
240240

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private suspend fun validateResponse(response: HttpResponse) {
293293
val htmlContentType = ContentType.Text.Html.withCharset(Charset.forName("utf-8"))
294294
if (response.status == HttpStatusCode.NotFound && response.contentType() == htmlContentType)
295295
throw ServerException(
296-
"""URL not found. Please verify the location used to create the `FirebaseVertexAI` object
296+
"""URL not found. Please verify the location used to create the `FirebaseAI` object
297297
| See https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions
298298
| for the list of available locations. Raw response: ${response.bodyAsText()}"""
299299
.trimMargin()
@@ -323,7 +323,7 @@ private suspend fun validateResponse(response: HttpResponse) {
323323
val errorMessage =
324324
if (it.metadata?.get("service") == "firebasevertexai.googleapis.com") {
325325
"""
326-
The Vertex AI in Firebase SDK requires the Vertex AI in Firebase API
326+
The Firebase AI SDK requires the Vertex AI in Firebase API
327327
(`firebasevertexai.googleapis.com`) to be enabled in your Firebase project. Enable this API
328328
by visiting the Firebase Console at
329329
https://console.firebase.google.com/project/${Firebase.options.projectId}/genai

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal data class CountTokensRequest(
5353
) : Request {
5454
companion object {
5555

56-
fun forGenAI(generateContentRequest: GenerateContentRequest) =
56+
fun forGoogleAI(generateContentRequest: GenerateContentRequest) =
5757
CountTokensRequest(
5858
generateContentRequest =
5959
generateContentRequest.model?.let {

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal constructor(message: String, cause: Throwable? = null) : RuntimeExcepti
7070

7171
/**
7272
* Catch any exception thrown in the [callback] block and rethrow it as a
73-
* [FirebaseVertexAIException].
73+
* [FirebaseAIException].
7474
*
7575
* Will return whatever the [callback] returns as well.
7676
*

firebase-ai/src/test/java/com/google/firebase/ai/common/util/descriptorToJson.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ internal fun typeNameFromKind(kind: SerialKind): String {
144144
* Our serialization classes are nested within the public-facing classes, and that's the name we
145145
* want in the json output. There are two class names
146146
*
147-
* - `com.google.firebase.vertexai.type.Content.Internal` for regular scenarios
148-
* - `com.google.firebase.vertexai.type.Content.Internal.SomeClass` for nested classes in the
147+
* - `com.google.firebase.ai.type.Content.Internal` for regular scenarios
148+
* - `com.google.firebase.ai.type.Content.Internal.SomeClass` for nested classes in the
149149
* serializer.
150150
*
151151
* For the later time we need the second to last component, for the former we need the last

0 commit comments

Comments
 (0)