Skip to content
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
4 changes: 4 additions & 0 deletions packages/firebase_ai/firebase_ai/lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ enum FinishReason {
/// The candidate content was flagged for recitation reasons.
recitation('RECITATION'),

/// The candidate content was flagged for malformed function call reasons.
malformedFunctionCall('MALFORMED_FUNCTION_CALL'),

/// Unknown reason.
other('OTHER');

Expand All @@ -770,6 +773,7 @@ enum FinishReason {
'SAFETY' => FinishReason.safety,
'RECITATION' => FinishReason.recitation,
'OTHER' => FinishReason.other,
'MALFORMED_FUNCTION_CALL' => FinishReason.malformedFunctionCall,
_ => throw FormatException('Unhandled FinishReason format', jsonObject),
};
}
Expand Down
14 changes: 14 additions & 0 deletions packages/firebase_ai/firebase_ai/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ void main() {
expect(FinishReason.maxTokens.toJson(), 'MAX_TOKENS');
expect(FinishReason.safety.toJson(), 'SAFETY');
expect(FinishReason.recitation.toJson(), 'RECITATION');
expect(FinishReason.malformedFunctionCall.toJson(),
'MALFORMED_FUNCTION_CALL');
expect(FinishReason.other.toJson(), 'OTHER');
});

Expand Down Expand Up @@ -973,6 +975,18 @@ void main() {
(e) => e.message, 'message', contains('WebGroundingChunk'))));
});

test('parses malformedFunctionCall finishReason', () {
final jsonResponse = {
'candidates': [
{'finishReason': 'MALFORMED_FUNCTION_CALL'}
]
};
final response =
VertexSerialization().parseGenerateContentResponse(jsonResponse);
expect(response.candidates.first.finishReason,
FinishReason.malformedFunctionCall);
});

test(
'parses groundingSupport and filters out entries without a segment',
() {
Expand Down
Loading