diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 3244c980674..caecad52c9f 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* [fixed] Fixed a serialization error that was thrown for the last message when using + `generateContentStream()` with `googleAI()`. * [fixed] Fixed `FirebaseAI.getInstance` StackOverflowException (#6971) * [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API. * [changed] Introduced the `Voice` class, which accepts a voice name, and deprecated the `Voices` class. diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Content.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Content.kt index 4e9f1a860db..c5f6fd21ea1 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Content.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Content.kt @@ -90,7 +90,7 @@ constructor(public val role: String? = "user", public val parts: List) { @Serializable internal data class Internal( @EncodeDefault val role: String? = "user", - val parts: List + val parts: List = emptyList() ) { internal fun toPublic(): Content { val returnedParts = diff --git a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt index 967254a096c..00fca396938 100644 --- a/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt +++ b/firebase-ai/src/test/java/com/google/firebase/ai/DevAPIStreamingSnapshotTests.kt @@ -88,6 +88,21 @@ internal class DevAPIStreamingSnapshotTests { } } + @Test + fun `streaming returned the last Content without parts`() = + goldenDevAPIStreamingFile("streaming-success-no-content-parts.txt") { + val responses = model.generateContentStream("prompt") + + withTimeout(testTimeout) { + val responseList = responses.toList() + responseList.isEmpty() shouldBe false + responseList.last().candidates.first().apply { + finishReason shouldBe FinishReason.STOP + content.parts.isEmpty() shouldBe false + } + } + } + @Test fun `stopped for recitation`() = goldenDevAPIStreamingFile("streaming-failure-recitation-no-content.txt") {