Skip to content

fix(ai): fix serialization for Content with no parts field #6964

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
@Serializable
internal data class Internal(
@EncodeDefault val role: String? = "user",
val parts: List<InternalPart>
val parts: List<InternalPart> = emptyList()
) {
internal fun toPublic(): Content {
val returnedParts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading