diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 0042f361afc..879b44b10b7 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -13,3 +13,4 @@ * [fixed] Fixed an issue with `LiveContentResponse` audio data not being present when the model was interrupted or the turn completed. (#6870) * [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870) +* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6922) diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index 69356ef118d..c8897a7f2c6 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -330,11 +330,13 @@ package com.google.firebase.ai.type { ctor public GenerateContentResponse(java.util.List candidates, com.google.firebase.ai.type.PromptFeedback? promptFeedback, com.google.firebase.ai.type.UsageMetadata? usageMetadata); method public java.util.List getCandidates(); method public java.util.List getFunctionCalls(); + method public java.util.List getInlineDataParts(); method public com.google.firebase.ai.type.PromptFeedback? getPromptFeedback(); method public String? getText(); method public com.google.firebase.ai.type.UsageMetadata? getUsageMetadata(); property public final java.util.List candidates; property public final java.util.List functionCalls; + property public final java.util.List inlineDataParts; property public final com.google.firebase.ai.type.PromptFeedback? promptFeedback; property public final String? text; property public final com.google.firebase.ai.type.UsageMetadata? usageMetadata; diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerateContentResponse.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerateContentResponse.kt index 21dfc5d1e88..be2b50f3be4 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerateContentResponse.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerateContentResponse.kt @@ -44,6 +44,18 @@ public class GenerateContentResponse( candidates.first().content.parts.filterIsInstance() } + /** + * Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist. + * + * This also includes any [ImagePart], but they will be represented as [InlineDataPart] instead. + */ + public val inlineDataParts: List by lazy { + candidates.first().content.parts.let { parts -> + parts.filterIsInstance().map { it.toInlineDataPart() } + + parts.filterIsInstance() + } + } + @Serializable internal data class Internal( val candidates: List? = null,