Skip to content
Prev Previous commit
Next Next commit
add the check for other getters in Content to exclude thought content
  • Loading branch information
cynthiajoan committed Aug 21, 2025
commit 102c5b6c0fb5549859ec582bc4701dc155e8ef6b
17 changes: 13 additions & 4 deletions packages/firebase_ai/firebase_ai/lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ final class GenerateContentResponse {
),
// Special case for a single TextPart to avoid iterable chain.
[
Candidate(content: Content(parts: [TextPart(isThought: final isThought, :final text)])),
Candidate(
content: Content(
parts: [TextPart(isThought: final isThought, :final text)]
)
),
...
] when isThought != true =>
]
when isThought != true =>
text,
[Candidate(content: Content(:final parts)), ...]
when parts.any((p) => p is TextPart && p.isThought != true) =>
Expand All @@ -117,7 +122,9 @@ final class GenerateContentResponse {
/// candidate has no [FunctionCall] parts. There is no error thrown if the
/// prompt or response were blocked.
Iterable<FunctionCall> get functionCalls =>
candidates.firstOrNull?.content.parts.whereType<FunctionCall>() ??
candidates.firstOrNull?.content.parts
.whereType<FunctionCall>()
.where((p) => p.isThought != true) ??
const [];

/// The inline data parts of the first candidate in [candidates], if any.
Expand All @@ -126,7 +133,9 @@ final class GenerateContentResponse {
/// candidate has no [InlineDataPart] parts. There is no error thrown if the
/// prompt or response were blocked.
Iterable<InlineDataPart> get inlineDataParts =>
candidates.firstOrNull?.content.parts.whereType<InlineDataPart>() ??
candidates.firstOrNull?.content.parts
.whereType<InlineDataPart>()
.where((p) => p.isThought != true) ??
const [];

/// The thought summary of the first candidate in [candidates], if any.
Expand Down