Skip to content

Add inlineDataParts helper property #6922

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

Merged
merged 3 commits into from
Apr 29, 2025
Merged
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
1 change: 1 addition & 0 deletions firebase-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions firebase-ai/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ package com.google.firebase.ai.type {
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);
method public java.util.List<com.google.firebase.ai.type.Candidate> getCandidates();
method public java.util.List<com.google.firebase.ai.type.FunctionCallPart> getFunctionCalls();
method public java.util.List<com.google.firebase.ai.type.InlineDataPart> 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<com.google.firebase.ai.type.Candidate> candidates;
property public final java.util.List<com.google.firebase.ai.type.FunctionCallPart> functionCalls;
property public final java.util.List<com.google.firebase.ai.type.InlineDataPart> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public class GenerateContentResponse(
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
}

/**
* 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<InlineDataPart> by lazy {
candidates.first().content.parts.let { parts ->
parts.filterIsInstance<ImagePart>().map { it.toInlineDataPart() } +
parts.filterIsInstance<InlineDataPart>()
}
}

@Serializable
internal data class Internal(
val candidates: List<Candidate.Internal>? = null,
Expand Down
Loading