Skip to content

Commit cd92cef

Browse files
committed
update parts
1 parent a182700 commit cd92cef

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public class GenerateContentResponse(
4646

4747
/** Convenience field to list all the [InlineDataPart]s in the response, if they exist. */
4848
public val inlineDataParts: List<InlineDataPart> by lazy {
49-
candidates.first().content.parts.filterIsInstance<InlineDataPart>()
49+
candidates.first().content.parts.let { parts ->
50+
parts.filterIsInstance<ImagePart>().map { it.toInlineDataPart() } +
51+
parts.filterIsInstance<InlineDataPart>()
52+
}
5053
}
5154

5255
@Serializable

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ public class TextPart(public val text: String) : Part {
4545
*
4646
* @param image [Bitmap] to convert into a [Part]
4747
*/
48-
public class ImagePart(public val image: Bitmap) : Part
48+
public class ImagePart(public val image: Bitmap) : Part {
49+
50+
internal fun toInlineDataPart() =
51+
InlineDataPart(
52+
android.util.Base64.decode(encodeBitmapToBase64Png(image), BASE_64_FLAGS),
53+
"image/jpeg"
54+
)
55+
}
4956

5057
/**
5158
* Represents binary data with an associated MIME type sent to and received from requests.

0 commit comments

Comments
 (0)