Skip to content

Commit 7b1855d

Browse files
daymxnrlazo
andauthored
Prepare VertexAI SDK for release (#6941)
Per [b/414829218](https://b.corp.google.com/issues/414829218), This ensures the Vertex AI SDK is properly aligned for the upcoming release. More specifically, this PR does the following: - Adds deprecation notices for all the public classes and interfaces, **besides** the root `FirebaseVertexAI` class and the relevant extension methods. - Updates the golden file version. - Adds the change from #6925 for working around invalid `SafetyRating`(s). - Adds a changelog entry that aligns with the deprecation notices. - Adds the changes from #6939 for tracking bidi usage. - Adds the changes from #6910 for aligning the bidi protos. --------- Co-authored-by: Rodrigo Lazo <[email protected]>
1 parent 548dc28 commit 7b1855d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1415
-918
lines changed

firebase-vertexai/CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# Unreleased
2+
* [changed] **Renamed / Replaced:** Vertex AI in Firebase (`FirebaseVertexAI`) has been renamed and
3+
replaced by the new Firebase AI SDK: `FirebaseAI`. This is to accommodate the evolving set of
4+
supported features and services. Please migrate to the new `FirebaseAI` package. See details in the
5+
[migration guide](/docs/vertex-ai/migrate-to-latest-sdk).
6+
7+
Note: Existing Vertex AI in Firebase users may continue to use the SDK and receive bug fixes but,
8+
going forward, new features will only be added into the new Firebase AI SDK.
9+
* [changed] **Breaking Change**: Removed the `LiveContentResponse.Status` class, and instead have nested the status
10+
fields as properties of `LiveContentResponse`. (#6941)
11+
* [changed] **Breaking Change**: Removed the `LiveContentResponse` class, and instead have provided subclasses
12+
of `LiveServerMessage` that match the responses from the model. (#6941)
13+
* [feature] Added support for the `id` field on `FunctionResponsePart` and `FunctionCallPart`. (#6941)
14+
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6941)
215

316

417
# 16.4.0

firebase-vertexai/api.txt

+703-679
Large diffs are not rendered by default.

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/Chat.kt

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import kotlinx.coroutines.flow.onEach
4444
* from the model. This will be provided to the model for each message sent (as context for the
4545
* discussion).
4646
*/
47+
@Deprecated(
48+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
49+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
50+
)
4751
public class Chat(
4852
private val model: GenerativeModel,
4953
public val history: MutableList<Content> = ArrayList()

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import com.google.firebase.vertexai.type.Tool
3737
import com.google.firebase.vertexai.type.ToolConfig
3838
import kotlin.coroutines.CoroutineContext
3939

40-
/** Entry point for all _Vertex AI for Firebase_ functionality. */
40+
/** Entry point for all _Vertex AI in Firebase_ functionality. */
4141
public class FirebaseVertexAI
4242
internal constructor(
4343
private val firebaseApp: FirebaseApp,

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAIMultiResourceComponent.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.google.firebase.inject.Provider
2525
import kotlin.coroutines.CoroutineContext
2626

2727
/**
28-
* Multi-resource container for Firebase Vertex AI.
28+
* Multi-resource container for Vertex AI in Firebase.
2929
*
3030
* @hide
3131
*/

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

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import kotlinx.serialization.ExperimentalSerializationApi
4747
* Represents a multimodal model (like Gemini), capable of generating content based on various input
4848
* types.
4949
*/
50+
@Deprecated(
51+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
52+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
53+
)
5054
public class GenerativeModel
5155
internal constructor(
5256
private val modelName: String,

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/ImagenModel.kt

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import com.google.firebase.vertexai.type.RequestOptions
3636
* types.
3737
*/
3838
@PublicPreviewAPI
39+
@Deprecated(
40+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
41+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
42+
)
3943
public class ImagenModel
4044
internal constructor(
4145
private val modelName: String,

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/LiveGenerativeModel.kt

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ import kotlinx.serialization.json.JsonObject
4646
* various input types, supporting bidirectional streaming.
4747
*/
4848
@PublicPreviewAPI
49+
@Deprecated(
50+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
51+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
52+
)
4953
public class LiveGenerativeModel
5054
internal constructor(
5155
private val modelName: String,

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ internal constructor(
164164
"wss://firebasevertexai.googleapis.com/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/$location?key=$key"
165165

166166
suspend fun getWebSocketSession(location: String): ClientWebSocketSession =
167-
client.webSocketSession(getBidiEndpoint(location))
167+
client.webSocketSession(getBidiEndpoint(location)) { applyCommonHeaders() }
168168

169169
fun generateContentStream(
170170
request: GenerateContentRequest
@@ -197,6 +197,11 @@ internal constructor(
197197
is CountTokensRequest -> setBody<CountTokensRequest>(request)
198198
is GenerateImageRequest -> setBody<GenerateImageRequest>(request)
199199
}
200+
201+
applyCommonHeaders()
202+
}
203+
204+
private fun HttpRequestBuilder.applyCommonHeaders() {
200205
contentType(ContentType.Application.Json)
201206
header("x-goog-api-key", key)
202207
header("x-goog-api-client", apiClient)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ChatFutures.kt

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import org.reactivestreams.Publisher
3030
*
3131
* @see [Chat]
3232
*/
33+
@Deprecated(
34+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
35+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
36+
)
3337
public abstract class ChatFutures internal constructor() {
3438

3539
/**

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/GenerativeModelFutures.kt

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import org.reactivestreams.Publisher
3232
*
3333
* @see [GenerativeModel]
3434
*/
35+
@Deprecated(
36+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
37+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
38+
)
3539
public abstract class GenerativeModelFutures internal constructor() {
3640

3741
/**

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ImagenModelFutures.kt

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import com.google.firebase.vertexai.type.PublicPreviewAPI
2929
* @see [ImagenModel]
3030
*/
3131
@PublicPreviewAPI
32+
@Deprecated(
33+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
34+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
35+
)
3236
public abstract class ImagenModelFutures internal constructor() {
3337
/**
3438
* Generates an image, returning the result directly to the caller.

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/LiveModelFutures.kt

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedExcepti
2828
* @see [LiveGenerativeModel]
2929
*/
3030
@PublicPreviewAPI
31+
@Deprecated(
32+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
33+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
34+
)
3135
public abstract class LiveModelFutures internal constructor() {
3236

3337
/**

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/LiveSessionFutures.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.google.common.util.concurrent.ListenableFuture
2323
import com.google.firebase.vertexai.type.Content
2424
import com.google.firebase.vertexai.type.FunctionCallPart
2525
import com.google.firebase.vertexai.type.FunctionResponsePart
26-
import com.google.firebase.vertexai.type.LiveContentResponse
26+
import com.google.firebase.vertexai.type.LiveServerMessage
2727
import com.google.firebase.vertexai.type.LiveSession
2828
import com.google.firebase.vertexai.type.MediaData
2929
import com.google.firebase.vertexai.type.PublicPreviewAPI
@@ -38,6 +38,10 @@ import org.reactivestreams.Publisher
3838
* @see [LiveSession]
3939
*/
4040
@PublicPreviewAPI
41+
@Deprecated(
42+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
43+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
44+
)
4145
public abstract class LiveSessionFutures internal constructor() {
4246

4347
/**
@@ -135,16 +139,16 @@ public abstract class LiveSessionFutures internal constructor() {
135139
*
136140
* Call [close] to stop receiving responses from the model.
137141
*
138-
* @return A [Publisher] which will emit [LiveContentResponse] from the model.
142+
* @return A [Publisher] which will emit [LiveServerMessage] from the model.
139143
*
140144
* @throws [SessionAlreadyReceivingException] when the session is already receiving.
141145
* @see stopReceiving
142146
*/
143-
public abstract fun receive(): Publisher<LiveContentResponse>
147+
public abstract fun receive(): Publisher<LiveServerMessage>
144148

145149
private class FuturesImpl(private val session: LiveSession) : LiveSessionFutures() {
146150

147-
override fun receive(): Publisher<LiveContentResponse> = session.receive().asPublisher()
151+
override fun receive(): Publisher<LiveServerMessage> = session.receive().asPublisher()
148152

149153
override fun close(): ListenableFuture<Unit> =
150154
SuspendToFutureAdapter.launchFuture { session.close() }

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt

+40-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import kotlinx.serialization.json.JsonNames
3434
* @property citationMetadata Metadata about the sources used to generate this content.
3535
* @property finishReason The reason the model stopped generating content, if it exist.
3636
*/
37+
@Deprecated(
38+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
39+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
40+
)
3741
public class Candidate
3842
internal constructor(
3943
public val content: Content,
@@ -51,7 +55,7 @@ internal constructor(
5155
val groundingMetadata: GroundingMetadata? = null,
5256
) {
5357
internal fun toPublic(): Candidate {
54-
val safetyRatings = safetyRatings?.map { it.toPublic() }.orEmpty()
58+
val safetyRatings = safetyRatings?.mapNotNull { it.toPublic() }.orEmpty()
5559
val citations = citationMetadata?.toPublic()
5660
val finishReason = finishReason?.toPublic()
5761

@@ -106,6 +110,10 @@ internal constructor(
106110
* @property severity The severity of the potential harm.
107111
* @property severityScore A numerical score representing the severity of harm.
108112
*/
113+
@Deprecated(
114+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
115+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
116+
)
109117
public class SafetyRating
110118
internal constructor(
111119
public val category: HarmCategory,
@@ -120,23 +128,32 @@ internal constructor(
120128
internal data class Internal
121129
@JvmOverloads
122130
constructor(
123-
val category: HarmCategory.Internal,
124-
val probability: HarmProbability.Internal,
131+
val category: HarmCategory.Internal? = null,
132+
val probability: HarmProbability.Internal? = null,
125133
val blocked: Boolean? = null, // TODO(): any reason not to default to false?
126134
val probabilityScore: Float? = null,
127135
val severity: HarmSeverity.Internal? = null,
128136
val severityScore: Float? = null,
129137
) {
130138

131139
internal fun toPublic() =
132-
SafetyRating(
133-
category = category.toPublic(),
134-
probability = probability.toPublic(),
135-
probabilityScore = probabilityScore ?: 0f,
136-
blocked = blocked,
137-
severity = severity?.toPublic(),
138-
severityScore = severityScore
139-
)
140+
/**
141+
* Due to a bug in the backend, it's possible that we receive an invalid `SafetyRating` value,
142+
* without either category or probability. We return null in those cases to enable filtering
143+
* by the higher level types.
144+
*/
145+
if (category == null || probability == null) {
146+
null
147+
} else {
148+
SafetyRating(
149+
category = category.toPublic(),
150+
probability = probability.toPublic(),
151+
probabilityScore = probabilityScore ?: 0f,
152+
blocked = blocked,
153+
severity = severity?.toPublic(),
154+
severityScore = severityScore
155+
)
156+
}
140157
}
141158
}
142159

@@ -146,6 +163,10 @@ internal constructor(
146163
* @property citations A list of individual cited sources and the parts of the content to which they
147164
* apply.
148165
*/
166+
@Deprecated(
167+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
168+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
169+
)
149170
public class CitationMetadata internal constructor(public val citations: List<Citation>) {
150171

151172
@Serializable
@@ -173,6 +194,10 @@ public class CitationMetadata internal constructor(public val citations: List<Ci
173194
* @property license The license under which the cited content is distributed under, if available.
174195
* @property publicationDate The date of publication of the cited source, if available.
175196
*/
197+
@Deprecated(
198+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
199+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
200+
)
176201
public class Citation
177202
internal constructor(
178203
public val title: String? = null,
@@ -239,6 +264,10 @@ internal constructor(
239264
* @property name The name of the finish reason.
240265
* @property ordinal The ordinal value of the finish reason.
241266
*/
267+
@Deprecated(
268+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
269+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
270+
)
242271
public class FinishReason private constructor(public val name: String, public val ordinal: Int) {
243272

244273
@Serializable(Internal.Serializer::class)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import kotlinx.serialization.Serializable
3131
* `"user"`.
3232
* @param parts An ordered list of [Part] that constitute this content.
3333
*/
34+
@Deprecated(
35+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
36+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
37+
)
3438
public class Content
3539
@JvmOverloads
3640
constructor(public val role: String? = "user", public val parts: List<Part>) {
@@ -41,6 +45,10 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
4145
}
4246

4347
/** Builder class to facilitate constructing complex [Content] objects. */
48+
@Deprecated(
49+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
50+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
51+
)
4452
public class Builder {
4553

4654
/** The producer of the content. Must be either 'user' or 'model'. By default, it's "user". */

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ContentModality.kt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import kotlinx.serialization.SerialName
2222
import kotlinx.serialization.Serializable
2323

2424
/** Content part modality. */
25+
@Deprecated(
26+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
27+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
28+
)
2529
public class ContentModality private constructor(public val ordinal: Int) {
2630

2731
@Serializable(Internal.Serializer::class)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import kotlinx.serialization.Serializable
3333
* @property promptTokensDetails The breakdown, by modality, of how many tokens are consumed by the
3434
* prompt.
3535
*/
36+
@Deprecated(
37+
"""The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.
38+
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
39+
)
3640
public class CountTokensResponse(
3741
public val totalTokens: Int,
3842
public val totalBillableCharacters: Int? = null,

0 commit comments

Comments
 (0)