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 @@ -770,6 +770,9 @@ enum FinishReason {
/// The candidate content was flagged for malformed function call reasons.
malformedFunctionCall('MALFORMED_FUNCTION_CALL'),

/// The model produced an unexpected tool call.
unexpectedToolCall('UNEXPECTED_TOOL_CALL'),

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

Expand All @@ -790,6 +793,7 @@ enum FinishReason {
'RECITATION' => FinishReason.recitation,
'OTHER' => FinishReason.other,
'MALFORMED_FUNCTION_CALL' => FinishReason.malformedFunctionCall,
'UNEXPECTED_TOOL_CALL' => FinishReason.unexpectedToolCall,
_ => throw FormatException('Unhandled FinishReason format', jsonObject),
};
}
Expand Down
13 changes: 13 additions & 0 deletions packages/firebase_ai/firebase_ai/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ void main() {
expect(FinishReason.recitation.toJson(), 'RECITATION');
expect(FinishReason.malformedFunctionCall.toJson(),
'MALFORMED_FUNCTION_CALL');
expect(FinishReason.unexpectedToolCall.toJson(), 'UNEXPECTED_TOOL_CALL');
expect(FinishReason.other.toJson(), 'OTHER');
});

Expand Down Expand Up @@ -1048,6 +1049,18 @@ void main() {
FinishReason.malformedFunctionCall);
});

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

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