Skip to content

Commit 4806c60

Browse files
committed
feat(firebase_ai): add malformedFunctionCall reason to FinishReason enum and update tests
1 parent 9cc9054 commit 4806c60

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/firebase_ai/firebase_ai/lib/src/api.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ enum FinishReason {
751751
/// The candidate content was flagged for recitation reasons.
752752
recitation('RECITATION'),
753753

754+
/// The candidate content was flagged for malformed function call reasons.
755+
malformedFunctionCall('MALFORMED_FUNCTION_CALL'),
756+
754757
/// Unknown reason.
755758
other('OTHER');
756759

@@ -770,6 +773,7 @@ enum FinishReason {
770773
'SAFETY' => FinishReason.safety,
771774
'RECITATION' => FinishReason.recitation,
772775
'OTHER' => FinishReason.other,
776+
'MALFORMED_FUNCTION_CALL' => FinishReason.malformedFunctionCall,
773777
_ => throw FormatException('Unhandled FinishReason format', jsonObject),
774778
};
775779
}

packages/firebase_ai/firebase_ai/test/api_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ void main() {
312312
expect(FinishReason.maxTokens.toJson(), 'MAX_TOKENS');
313313
expect(FinishReason.safety.toJson(), 'SAFETY');
314314
expect(FinishReason.recitation.toJson(), 'RECITATION');
315+
expect(FinishReason.malformedFunctionCall.toJson(),
316+
'MALFORMED_FUNCTION_CALL');
315317
expect(FinishReason.other.toJson(), 'OTHER');
316318
});
317319

@@ -973,6 +975,18 @@ void main() {
973975
(e) => e.message, 'message', contains('WebGroundingChunk'))));
974976
});
975977

978+
test('parses malformedFunctionCall finishReason', () {
979+
final jsonResponse = {
980+
'candidates': [
981+
{'finishReason': 'MALFORMED_FUNCTION_CALL'}
982+
]
983+
};
984+
final response =
985+
VertexSerialization().parseGenerateContentResponse(jsonResponse);
986+
expect(response.candidates.first.finishReason,
987+
FinishReason.malformedFunctionCall);
988+
});
989+
976990
test(
977991
'parses groundingSupport and filters out entries without a segment',
978992
() {

0 commit comments

Comments
 (0)