Skip to content

Migrate LiveContentResponse.Status to properties #6906

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 3 commits into from
Apr 24, 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
2 changes: 2 additions & 0 deletions firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
interrupted or the turn completed. (#6870)
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)
* [feature] Enable response generation in multiple modalities. (#6901)
* [changed] Removed the `LiveContentResponse.Status` class, and instead have nested the status
fields as properties of `LiveContentResponse`. (#6906)


# 16.3.0
Expand Down
19 changes: 4 additions & 15 deletions firebase-vertexai/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,25 +569,14 @@ package com.google.firebase.vertexai.type {
@com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveContentResponse {
method public com.google.firebase.vertexai.type.Content? getData();
method public java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>? getFunctionCalls();
method public int getStatus();
method public Boolean? getInterrupted();
method public String? getText();
method public Boolean? getTurnComplete();
property public final com.google.firebase.vertexai.type.Content? data;
property public final java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>? functionCalls;
property public final int status;
property public final Boolean? interrupted;
property public final String? text;
}

@kotlin.jvm.JvmInline public static final value class LiveContentResponse.Status {
field public static final com.google.firebase.vertexai.type.LiveContentResponse.Status.Companion Companion;
}

public static final class LiveContentResponse.Status.Companion {
method public int getINTERRUPTED();
method public int getNORMAL();
method public int getTURN_COMPLETE();
property public final int INTERRUPTED;
property public final int NORMAL;
property public final int TURN_COMPLETE;
property public final Boolean? turnComplete;
}

@com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveGenerationConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ internal constructor(
public val data: Content?,

/**
* The status of the live content response. Indicates whether the response is normal, was
* interrupted, or signifies the completion of a turn.
* The model was interrupted while generating data.
*
* An interruption occurs when the client sends a message while the model is actively sending
* data.
*/
public val interrupted: Boolean?,

/**
* The model has finished sending data in the current interaction.
*
* Can be set alongside content, signifying that the content is the last in the turn.
*/
public val status: Status,
public val turnComplete: Boolean?,

/**
* A list of [FunctionCallPart] included in the response, if any.
Expand All @@ -49,26 +58,4 @@ internal constructor(
*/
public val text: String? =
data?.parts?.filterIsInstance<TextPart>()?.joinToString(" ") { it.text }

/** Represents the status of a [LiveContentResponse], within a single interaction. */
@JvmInline
public value class Status private constructor(private val value: Int) {
public companion object {
/** The server is actively sending data for the current interaction. */
public val NORMAL: Status = Status(0)
/**
* The server was interrupted while generating data.
*
* An interruption occurs when the client sends a message while the server is [actively]
* [NORMAL] sending data.
*/
public val INTERRUPTED: Status = Status(1)
/**
* The model has finished sending data in the current interaction.
*
* Can be set alongside content, signifying that the content is the last in the turn.
*/
public val TURN_COMPLETE: Status = Status(2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal constructor(
) {
receive()
.transform {
if (it.status == LiveContentResponse.Status.INTERRUPTED) {
if (it.interrupted == true) {
playBackQueue.clear()
} else {
emit(it)
Expand Down Expand Up @@ -387,7 +387,8 @@ internal constructor(
JSON.decodeFromJsonElement<BidiGenerateContentToolCallSetup.Internal>(jsonMessage)
LiveContentResponse(
null,
LiveContentResponse.Status.NORMAL,
null,
null,
functionContent.toolCall.functionCalls.map {
FunctionCallPart(it.name, it.args.orEmpty().mapValues { x -> x.value ?: JsonNull })
}
Expand All @@ -397,13 +398,12 @@ internal constructor(
val serverContent =
JSON.decodeFromJsonElement<BidiGenerateContentServerContentSetup.Internal>(jsonMessage)
.serverContent
val status =
when {
serverContent.turnComplete == true -> LiveContentResponse.Status.TURN_COMPLETE
serverContent.interrupted == true -> LiveContentResponse.Status.INTERRUPTED
else -> LiveContentResponse.Status.NORMAL
}
LiveContentResponse(serverContent.modelTurn?.toPublic(), status, null)
LiveContentResponse(
serverContent.modelTurn?.toPublic(),
serverContent.interrupted,
serverContent.turnComplete,
null
)
}
else -> {
Log.w(TAG, "Failed to decode the server response: $jsonMessage")
Expand Down
Loading