Skip to content

Commit 4fb4dfd

Browse files
authored
Migrate LiveContentResponse.Status to properties (#6906)
Per [b/410855548](https://b.corp.google.com/issues/410855548), This removes the `LiveContentResponse.Status` class, and instead nests the status as corresponding fields directly on `LiveContentResponse`. This is done to ensure we can support the model returning multiple statuses, since the model does not define them as exclusive. Note that proto alignment efforts will be in a separate PR. This PR is _only_ for migrating `Status` to properties.
1 parent b0d8622 commit 4fb4dfd

File tree

4 files changed

+27
-49
lines changed

4 files changed

+27
-49
lines changed

firebase-vertexai/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
interrupted or the turn completed. (#6870)
1515
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)
1616
* [feature] Enable response generation in multiple modalities. (#6901)
17+
* [changed] Removed the `LiveContentResponse.Status` class, and instead have nested the status
18+
fields as properties of `LiveContentResponse`. (#6906)
1719

1820

1921
# 16.3.0

firebase-vertexai/api.txt

+4-15
Original file line numberDiff line numberDiff line change
@@ -569,25 +569,14 @@ package com.google.firebase.vertexai.type {
569569
@com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveContentResponse {
570570
method public com.google.firebase.vertexai.type.Content? getData();
571571
method public java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>? getFunctionCalls();
572-
method public int getStatus();
572+
method public Boolean? getInterrupted();
573573
method public String? getText();
574+
method public Boolean? getTurnComplete();
574575
property public final com.google.firebase.vertexai.type.Content? data;
575576
property public final java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>? functionCalls;
576-
property public final int status;
577+
property public final Boolean? interrupted;
577578
property public final String? text;
578-
}
579-
580-
@kotlin.jvm.JvmInline public static final value class LiveContentResponse.Status {
581-
field public static final com.google.firebase.vertexai.type.LiveContentResponse.Status.Companion Companion;
582-
}
583-
584-
public static final class LiveContentResponse.Status.Companion {
585-
method public int getINTERRUPTED();
586-
method public int getNORMAL();
587-
method public int getTURN_COMPLETE();
588-
property public final int INTERRUPTED;
589-
property public final int NORMAL;
590-
property public final int TURN_COMPLETE;
579+
property public final Boolean? turnComplete;
591580
}
592581

593582
@com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveGenerationConfig {

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

+12-25
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ internal constructor(
3030
public val data: Content?,
3131

3232
/**
33-
* The status of the live content response. Indicates whether the response is normal, was
34-
* interrupted, or signifies the completion of a turn.
33+
* The model was interrupted while generating data.
34+
*
35+
* An interruption occurs when the client sends a message while the model is actively sending
36+
* data.
37+
*/
38+
public val interrupted: Boolean?,
39+
40+
/**
41+
* The model has finished sending data in the current interaction.
42+
*
43+
* Can be set alongside content, signifying that the content is the last in the turn.
3544
*/
36-
public val status: Status,
45+
public val turnComplete: Boolean?,
3746

3847
/**
3948
* A list of [FunctionCallPart] included in the response, if any.
@@ -49,26 +58,4 @@ internal constructor(
4958
*/
5059
public val text: String? =
5160
data?.parts?.filterIsInstance<TextPart>()?.joinToString(" ") { it.text }
52-
53-
/** Represents the status of a [LiveContentResponse], within a single interaction. */
54-
@JvmInline
55-
public value class Status private constructor(private val value: Int) {
56-
public companion object {
57-
/** The server is actively sending data for the current interaction. */
58-
public val NORMAL: Status = Status(0)
59-
/**
60-
* The server was interrupted while generating data.
61-
*
62-
* An interruption occurs when the client sends a message while the server is [actively]
63-
* [NORMAL] sending data.
64-
*/
65-
public val INTERRUPTED: Status = Status(1)
66-
/**
67-
* The model has finished sending data in the current interaction.
68-
*
69-
* Can be set alongside content, signifying that the content is the last in the turn.
70-
*/
71-
public val TURN_COMPLETE: Status = Status(2)
72-
}
73-
}
7461
}

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ internal constructor(
310310
) {
311311
receive()
312312
.transform {
313-
if (it.status == LiveContentResponse.Status.INTERRUPTED) {
313+
if (it.interrupted == true) {
314314
playBackQueue.clear()
315315
} else {
316316
emit(it)
@@ -387,7 +387,8 @@ internal constructor(
387387
JSON.decodeFromJsonElement<BidiGenerateContentToolCallSetup.Internal>(jsonMessage)
388388
LiveContentResponse(
389389
null,
390-
LiveContentResponse.Status.NORMAL,
390+
null,
391+
null,
391392
functionContent.toolCall.functionCalls.map {
392393
FunctionCallPart(it.name, it.args.orEmpty().mapValues { x -> x.value ?: JsonNull })
393394
}
@@ -397,13 +398,12 @@ internal constructor(
397398
val serverContent =
398399
JSON.decodeFromJsonElement<BidiGenerateContentServerContentSetup.Internal>(jsonMessage)
399400
.serverContent
400-
val status =
401-
when {
402-
serverContent.turnComplete == true -> LiveContentResponse.Status.TURN_COMPLETE
403-
serverContent.interrupted == true -> LiveContentResponse.Status.INTERRUPTED
404-
else -> LiveContentResponse.Status.NORMAL
405-
}
406-
LiveContentResponse(serverContent.modelTurn?.toPublic(), status, null)
401+
LiveContentResponse(
402+
serverContent.modelTurn?.toPublic(),
403+
serverContent.interrupted,
404+
serverContent.turnComplete,
405+
null
406+
)
407407
}
408408
else -> {
409409
Log.w(TAG, "Failed to decode the server response: $jsonMessage")

0 commit comments

Comments
 (0)