Skip to content

Commit f772112

Browse files
committed
Merge
1 parent d01fa54 commit f772112

File tree

1 file changed

+8
-2
lines changed
  • firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
8888
@EncodeDefault val role: String? = "user",
8989
val parts: List<InternalPart>
9090
) {
91-
92-
internal fun toPublic(): Content = Content(role, parts.map { it.toPublic() })
91+
internal fun toPublic(): Content {
92+
val returnedParts =
93+
parts.map { it.toPublic() }.filterNot { it is TextPart && it.text.isEmpty() }
94+
// If all returned parts were text and empty, we coalesce them into a single one-character
95+
// string
96+
// part so the backend doesn't fail if we send this back as part of a multi-turn interaction.
97+
return Content(role, returnedParts.ifEmpty { listOf(TextPart(" ")) })
98+
}
9399
}
94100
}
95101

0 commit comments

Comments
 (0)