Skip to content

Prepare VertexAI SDK for release #6941

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 15 commits into from
May 7, 2025
13 changes: 13 additions & 0 deletions firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Unreleased
* [changed] **Renamed / Replaced:** Vertex AI in Firebase (`FirebaseVertexAI`) has been renamed and
replaced by the new Firebase AI SDK: `FirebaseAI`. This is to accommodate the evolving set of
supported features and services. Please migrate to the new `FirebaseAI` package. See details in the
[migration guide](/docs/vertex-ai/migrate-to-latest-sdk).

Note: Existing Vertex AI in Firebase users may continue to use the SDK and receive bug fixes but,
going forward, new features will only be added into the new Firebase AI SDK.
* [changed] **Breaking Change**: Removed the `LiveContentResponse.Status` class, and instead have nested the status
fields as properties of `LiveContentResponse`. (#6941)
* [changed] **Breaking Change**: Removed the `LiveContentResponse` class, and instead have provided subclasses
of `LiveServerMessage` that match the responses from the model. (#6941)
* [feature] Added support for the `id` field on `FunctionResponsePart` and `FunctionCallPart`. (#6941)
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6941)


# 16.4.0
Expand Down
1,382 changes: 703 additions & 679 deletions firebase-vertexai/api.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import kotlinx.coroutines.flow.onEach
* from the model. This will be provided to the model for each message sent (as context for the
* discussion).
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class Chat(
private val model: GenerativeModel,
public val history: MutableList<Content> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.google.firebase.vertexai.type.Tool
import com.google.firebase.vertexai.type.ToolConfig
import kotlin.coroutines.CoroutineContext

/** Entry point for all _Vertex AI for Firebase_ functionality. */
/** Entry point for all _Vertex AI in Firebase_ functionality. */
public class FirebaseVertexAI
internal constructor(
private val firebaseApp: FirebaseApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.google.firebase.inject.Provider
import kotlin.coroutines.CoroutineContext

/**
* Multi-resource container for Firebase Vertex AI.
* Multi-resource container for Vertex AI in Firebase.
*
* @hide
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import kotlinx.serialization.ExperimentalSerializationApi
* Represents a multimodal model (like Gemini), capable of generating content based on various input
* types.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class GenerativeModel
internal constructor(
private val modelName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import com.google.firebase.vertexai.type.RequestOptions
* types.
*/
@PublicPreviewAPI
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class ImagenModel
internal constructor(
private val modelName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ import kotlinx.serialization.json.JsonObject
* various input types, supporting bidirectional streaming.
*/
@PublicPreviewAPI
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class LiveGenerativeModel
internal constructor(
private val modelName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal constructor(
"wss://firebasevertexai.googleapis.com/ws/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent/locations/$location?key=$key"

suspend fun getWebSocketSession(location: String): ClientWebSocketSession =
client.webSocketSession(getBidiEndpoint(location))
client.webSocketSession(getBidiEndpoint(location)) { applyCommonHeaders() }

fun generateContentStream(
request: GenerateContentRequest
Expand Down Expand Up @@ -197,6 +197,11 @@ internal constructor(
is CountTokensRequest -> setBody<CountTokensRequest>(request)
is GenerateImageRequest -> setBody<GenerateImageRequest>(request)
}

applyCommonHeaders()
}

private fun HttpRequestBuilder.applyCommonHeaders() {
contentType(ContentType.Application.Json)
header("x-goog-api-key", key)
header("x-goog-api-client", apiClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import org.reactivestreams.Publisher
*
* @see [Chat]
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public abstract class ChatFutures internal constructor() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import org.reactivestreams.Publisher
*
* @see [GenerativeModel]
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public abstract class GenerativeModelFutures internal constructor() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import com.google.firebase.vertexai.type.PublicPreviewAPI
* @see [ImagenModel]
*/
@PublicPreviewAPI
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public abstract class ImagenModelFutures internal constructor() {
/**
* Generates an image, returning the result directly to the caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedExcepti
* @see [LiveGenerativeModel]
*/
@PublicPreviewAPI
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public abstract class LiveModelFutures internal constructor() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.google.common.util.concurrent.ListenableFuture
import com.google.firebase.vertexai.type.Content
import com.google.firebase.vertexai.type.FunctionCallPart
import com.google.firebase.vertexai.type.FunctionResponsePart
import com.google.firebase.vertexai.type.LiveContentResponse
import com.google.firebase.vertexai.type.LiveServerMessage
import com.google.firebase.vertexai.type.LiveSession
import com.google.firebase.vertexai.type.MediaData
import com.google.firebase.vertexai.type.PublicPreviewAPI
Expand All @@ -38,6 +38,10 @@ import org.reactivestreams.Publisher
* @see [LiveSession]
*/
@PublicPreviewAPI
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public abstract class LiveSessionFutures internal constructor() {

/**
Expand Down Expand Up @@ -135,16 +139,16 @@ public abstract class LiveSessionFutures internal constructor() {
*
* Call [close] to stop receiving responses from the model.
*
* @return A [Publisher] which will emit [LiveContentResponse] from the model.
* @return A [Publisher] which will emit [LiveServerMessage] from the model.
*
* @throws [SessionAlreadyReceivingException] when the session is already receiving.
* @see stopReceiving
*/
public abstract fun receive(): Publisher<LiveContentResponse>
public abstract fun receive(): Publisher<LiveServerMessage>

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

override fun receive(): Publisher<LiveContentResponse> = session.receive().asPublisher()
override fun receive(): Publisher<LiveServerMessage> = session.receive().asPublisher()

override fun close(): ListenableFuture<Unit> =
SuspendToFutureAdapter.launchFuture { session.close() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import kotlinx.serialization.json.JsonNames
* @property citationMetadata Metadata about the sources used to generate this content.
* @property finishReason The reason the model stopped generating content, if it exist.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class Candidate
internal constructor(
public val content: Content,
Expand All @@ -51,7 +55,7 @@ internal constructor(
val groundingMetadata: GroundingMetadata? = null,
) {
internal fun toPublic(): Candidate {
val safetyRatings = safetyRatings?.map { it.toPublic() }.orEmpty()
val safetyRatings = safetyRatings?.mapNotNull { it.toPublic() }.orEmpty()
val citations = citationMetadata?.toPublic()
val finishReason = finishReason?.toPublic()

Expand Down Expand Up @@ -106,6 +110,10 @@ internal constructor(
* @property severity The severity of the potential harm.
* @property severityScore A numerical score representing the severity of harm.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class SafetyRating
internal constructor(
public val category: HarmCategory,
Expand All @@ -120,23 +128,32 @@ internal constructor(
internal data class Internal
@JvmOverloads
constructor(
val category: HarmCategory.Internal,
val probability: HarmProbability.Internal,
val category: HarmCategory.Internal? = null,
val probability: HarmProbability.Internal? = null,
val blocked: Boolean? = null, // TODO(): any reason not to default to false?
val probabilityScore: Float? = null,
val severity: HarmSeverity.Internal? = null,
val severityScore: Float? = null,
) {

internal fun toPublic() =
SafetyRating(
category = category.toPublic(),
probability = probability.toPublic(),
probabilityScore = probabilityScore ?: 0f,
blocked = blocked,
severity = severity?.toPublic(),
severityScore = severityScore
)
/**
* Due to a bug in the backend, it's possible that we receive an invalid `SafetyRating` value,
* without either category or probability. We return null in those cases to enable filtering
* by the higher level types.
*/
if (category == null || probability == null) {
null
} else {
SafetyRating(
category = category.toPublic(),
probability = probability.toPublic(),
probabilityScore = probabilityScore ?: 0f,
blocked = blocked,
severity = severity?.toPublic(),
severityScore = severityScore
)
}
}
}

Expand All @@ -146,6 +163,10 @@ internal constructor(
* @property citations A list of individual cited sources and the parts of the content to which they
* apply.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class CitationMetadata internal constructor(public val citations: List<Citation>) {

@Serializable
Expand Down Expand Up @@ -173,6 +194,10 @@ public class CitationMetadata internal constructor(public val citations: List<Ci
* @property license The license under which the cited content is distributed under, if available.
* @property publicationDate The date of publication of the cited source, if available.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class Citation
internal constructor(
public val title: String? = null,
Expand Down Expand Up @@ -239,6 +264,10 @@ internal constructor(
* @property name The name of the finish reason.
* @property ordinal The ordinal value of the finish reason.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class FinishReason private constructor(public val name: String, public val ordinal: Int) {

@Serializable(Internal.Serializer::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import kotlinx.serialization.Serializable
* `"user"`.
* @param parts An ordered list of [Part] that constitute this content.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class Content
@JvmOverloads
constructor(public val role: String? = "user", public val parts: List<Part>) {
Expand All @@ -41,6 +45,10 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
}

/** Builder class to facilitate constructing complex [Content] objects. */
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class Builder {

/** The producer of the content. Must be either 'user' or 'model'. By default, it's "user". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/** Content part modality. */
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class ContentModality private constructor(public val ordinal: Int) {

@Serializable(Internal.Serializer::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import kotlinx.serialization.Serializable
* @property promptTokensDetails The breakdown, by modality, of how many tokens are consumed by the
* prompt.
*/
@Deprecated(
"""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.
For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk"""
)
public class CountTokensResponse(
public val totalTokens: Int,
public val totalBillableCharacters: Int? = null,
Expand Down
Loading
Loading