Skip to content

Commit 1ff1618

Browse files
committed
Update LiveSession.kt
1 parent 87f1ffa commit 1ff1618

File tree

1 file changed

+34
-26
lines changed
  • firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type

1 file changed

+34
-26
lines changed

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

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ internal constructor(
214214
FirebaseVertexAIException.catchAsync {
215215
val jsonString =
216216
Json.encodeToString(
217-
LiveToolResponseSetup(functionList.map { it.toInternalFunctionCall() }).toInternal()
217+
BidiGenerateContentToolResponseSetup(functionList.map { it.toInternalFunctionCall() })
218+
.toInternal()
218219
)
219220
session.send(Frame.Text(jsonString))
220221
}
@@ -233,7 +234,7 @@ internal constructor(
233234
FirebaseVertexAIException.catchAsync {
234235
val jsonString =
235236
Json.encodeToString(
236-
LiveClientRealtimeInputSetup(mediaChunks.map { (it.toInternal()) }).toInternal()
237+
BidiGenerateContentRealtimeInputSetup(mediaChunks.map { (it.toInternal()) }).toInternal()
237238
)
238239
session.send(Frame.Text(jsonString))
239240
}
@@ -249,7 +250,9 @@ internal constructor(
249250
public suspend fun send(content: Content) {
250251
FirebaseVertexAIException.catchAsync {
251252
val jsonString =
252-
Json.encodeToString(LiveClientContentSetup(listOf(content.toInternal()), true).toInternal())
253+
Json.encodeToString(
254+
BidiGenerateContentClientContentSetup(listOf(content.toInternal()), true).toInternal()
255+
)
253256
session.send(Frame.Text(jsonString))
254257
}
255258
}
@@ -380,7 +383,8 @@ internal constructor(
380383

381384
return when {
382385
"toolCall" in jsonMessage -> {
383-
val functionContent = JSON.decodeFromJsonElement<LiveServerToolCall.Internal>(jsonMessage)
386+
val functionContent =
387+
JSON.decodeFromJsonElement<BidiGenerateContentToolCallSetup.Internal>(jsonMessage)
384388
LiveContentResponse(
385389
null,
386390
LiveContentResponse.Status.NORMAL,
@@ -391,7 +395,8 @@ internal constructor(
391395
}
392396
"serverContent" in jsonMessage -> {
393397
val serverContent =
394-
JSON.decodeFromJsonElement<LiveServerContentSetup.Internal>(jsonMessage).serverContent
398+
JSON.decodeFromJsonElement<BidiGenerateContentServerContentSetup.Internal>(jsonMessage)
399+
.serverContent
395400
val status =
396401
when {
397402
serverContent.turnComplete == true -> LiveContentResponse.Status.TURN_COMPLETE
@@ -412,92 +417,95 @@ internal constructor(
412417
*
413418
* Effectively, a message from the client to the model.
414419
*/
415-
internal class LiveClientContentSetup(
420+
internal class BidiGenerateContentClientContentSetup(
416421
val turns: List<Content.Internal>,
417422
val turnComplete: Boolean
418423
) {
419424
@Serializable
420-
internal class Internal(val clientContent: LiveClientContent) {
425+
internal class Internal(val clientContent: BidiGenerateContentClientContent) {
421426
@Serializable
422-
internal data class LiveClientContent(
427+
internal data class BidiGenerateContentClientContent(
423428
val turns: List<Content.Internal>,
424429
val turnComplete: Boolean
425430
)
426431
}
427432

428-
fun toInternal() = Internal(Internal.LiveClientContent(turns, turnComplete))
433+
fun toInternal() = Internal(Internal.BidiGenerateContentClientContent(turns, turnComplete))
429434
}
430435

431436
/**
432437
* Incremental server update generated by the model in response to client messages.
433438
*
434439
* Effectively, a message from the model to the client.
435440
*/
436-
internal class LiveServerContentSetup(
441+
internal class BidiGenerateContentServerContentSetup(
437442
val modelTurn: Content.Internal?,
438443
val turnComplete: Boolean?,
439444
val interrupted: Boolean?
440445
) {
441446
@Serializable
442-
internal class Internal(val serverContent: LiveServerContent) {
447+
internal class Internal(val serverContent: BidiGenerateContentServerContent) {
443448
@Serializable
444-
internal data class LiveServerContent(
449+
internal data class BidiGenerateContentServerContent(
445450
val modelTurn: Content.Internal?,
446451
val turnComplete: Boolean?,
447452
val interrupted: Boolean?
448453
)
449454
}
450455

451-
fun toInternal() = Internal(Internal.LiveServerContent(modelTurn, turnComplete, interrupted))
456+
fun toInternal() =
457+
Internal(Internal.BidiGenerateContentServerContent(modelTurn, turnComplete, interrupted))
452458
}
453459

454460
/**
455461
* Request for the client to execute the provided function calls and return the responses with the
456462
* matched `id`s.
457463
*/
458-
internal data class LiveServerToolCall(
464+
internal data class BidiGenerateContentToolCallSetup(
459465
val functionCalls: List<FunctionCallPart.Internal.FunctionCall>
460466
) {
461467
@Serializable
462-
internal class Internal(val toolCall: LiveServerToolCall) {
468+
internal class Internal(val toolCall: BidiGenerateContentToolCall) {
463469
@Serializable
464-
internal data class LiveServerToolCall(
470+
internal data class BidiGenerateContentToolCall(
465471
val functionCalls: List<FunctionCallPart.Internal.FunctionCall>
466472
)
467473
}
468474

469475
fun toInternal(): Internal {
470-
return Internal(Internal.LiveServerToolCall(functionCalls))
476+
return Internal(Internal.BidiGenerateContentToolCall(functionCalls))
471477
}
472478
}
473479

474-
/** Client generated responses to a [LiveServerToolCall]. */
475-
internal class LiveToolResponseSetup(
480+
/** Client generated responses to a [BidiGenerateContentToolCallSetup]. */
481+
internal class BidiGenerateContentToolResponseSetup(
476482
val functionResponses: List<FunctionResponsePart.Internal.FunctionResponse>
477483
) {
478484
@Serializable
479-
internal data class Internal(val toolResponse: LiveToolResponse) {
485+
internal data class Internal(val toolResponse: BidiGenerateContentToolResponse) {
480486
@Serializable
481-
internal data class LiveToolResponse(
487+
internal data class BidiGenerateContentToolResponse(
482488
val functionResponses: List<FunctionResponsePart.Internal.FunctionResponse>
483489
)
484490
}
485491

486-
fun toInternal() = Internal(Internal.LiveToolResponse(functionResponses))
492+
fun toInternal() = Internal(Internal.BidiGenerateContentToolResponse(functionResponses))
487493
}
488494

489495
/**
490496
* User input that is sent to the model in real time.
491497
*
492498
* End of turn is derived from user activity (eg; end of speech).
493499
*/
494-
internal class LiveClientRealtimeInputSetup(val mediaChunks: List<MediaData.Internal>) {
500+
internal class BidiGenerateContentRealtimeInputSetup(val mediaChunks: List<MediaData.Internal>) {
495501
@Serializable
496-
internal class Internal(val realtimeInput: LiveClientRealtimeInput) {
502+
internal class Internal(val realtimeInput: BidiGenerateContentRealtimeInput) {
497503
@Serializable
498-
internal data class LiveClientRealtimeInput(val mediaChunks: List<MediaData.Internal>)
504+
internal data class BidiGenerateContentRealtimeInput(
505+
val mediaChunks: List<MediaData.Internal>
506+
)
499507
}
500-
fun toInternal() = Internal(Internal.LiveClientRealtimeInput(mediaChunks))
508+
fun toInternal() = Internal(Internal.BidiGenerateContentRealtimeInput(mediaChunks))
501509
}
502510

503511
private companion object {

0 commit comments

Comments
 (0)