Skip to content

Commit a879354

Browse files
authored
Add inlineDataParts helper property (#6922)
Per [b/414639898](https://b.corp.google.com/issues/414639898), This adds a helper property to `GenerateContentResponse` for getting all the `InlineDataPart` present in the first candidate, similar to `text`. This was actually added in #6901, but it seems to have been missed during our `firebase-ai` migration.
1 parent a6010b2 commit a879354

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

firebase-ai/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
* [fixed] Fixed an issue with `LiveContentResponse` audio data not being present when the model was
1414
interrupted or the turn completed. (#6870)
1515
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)
16+
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6922)

firebase-ai/api.txt

+2
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ package com.google.firebase.ai.type {
330330
ctor public GenerateContentResponse(java.util.List<com.google.firebase.ai.type.Candidate> candidates, com.google.firebase.ai.type.PromptFeedback? promptFeedback, com.google.firebase.ai.type.UsageMetadata? usageMetadata);
331331
method public java.util.List<com.google.firebase.ai.type.Candidate> getCandidates();
332332
method public java.util.List<com.google.firebase.ai.type.FunctionCallPart> getFunctionCalls();
333+
method public java.util.List<com.google.firebase.ai.type.InlineDataPart> getInlineDataParts();
333334
method public com.google.firebase.ai.type.PromptFeedback? getPromptFeedback();
334335
method public String? getText();
335336
method public com.google.firebase.ai.type.UsageMetadata? getUsageMetadata();
336337
property public final java.util.List<com.google.firebase.ai.type.Candidate> candidates;
337338
property public final java.util.List<com.google.firebase.ai.type.FunctionCallPart> functionCalls;
339+
property public final java.util.List<com.google.firebase.ai.type.InlineDataPart> inlineDataParts;
338340
property public final com.google.firebase.ai.type.PromptFeedback? promptFeedback;
339341
property public final String? text;
340342
property public final com.google.firebase.ai.type.UsageMetadata? usageMetadata;

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

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public class GenerateContentResponse(
4444
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
4545
}
4646

47+
/**
48+
* Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist.
49+
*
50+
* This also includes any [ImagePart], but they will be represented as [InlineDataPart] instead.
51+
*/
52+
public val inlineDataParts: List<InlineDataPart> by lazy {
53+
candidates.first().content.parts.let { parts ->
54+
parts.filterIsInstance<ImagePart>().map { it.toInlineDataPart() } +
55+
parts.filterIsInstance<InlineDataPart>()
56+
}
57+
}
58+
4759
@Serializable
4860
internal data class Internal(
4961
val candidates: List<Candidate.Internal>? = null,

0 commit comments

Comments
 (0)