Skip to content

Commit 92469fe

Browse files
authored
fix the optional attributes while parsing SafetyRating (#13452)
1 parent d29dde4 commit 92469fe

File tree

1 file changed

+11
-17
lines changed
  • packages/firebase_vertexai/firebase_vertexai/lib/src

1 file changed

+11
-17
lines changed

packages/firebase_vertexai/firebase_vertexai/lib/src/api.dart

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -784,23 +784,17 @@ UsageMetadata _parseUsageMetadata(Object jsonObject) {
784784
}
785785

786786
SafetyRating _parseSafetyRating(Object? jsonObject) {
787-
return switch (jsonObject) {
788-
{
789-
'category': final Object category,
790-
'probability': final Object probability,
791-
'probabilityScore': final double probabilityScore,
792-
'blocked': final bool blocked,
793-
'severity': final Object severity,
794-
'severityScore': final double severityScore?,
795-
} =>
796-
SafetyRating(HarmCategory._parseValue(category),
797-
HarmProbability._parseValue(probability),
798-
probabilityScore: probabilityScore,
799-
isBlocked: blocked,
800-
severity: HarmSeverity._parseValue(severity),
801-
severityScore: severityScore),
802-
_ => throw unhandledFormat('SafetyRating', jsonObject),
803-
};
787+
if (jsonObject is! Map) {
788+
throw unhandledFormat('SafetyRating', jsonObject);
789+
}
790+
return SafetyRating(HarmCategory._parseValue(jsonObject['category']),
791+
HarmProbability._parseValue(jsonObject['probability']),
792+
probabilityScore: jsonObject['probabilityScore'] as double?,
793+
isBlocked: jsonObject['blocked'] as bool?,
794+
severity: jsonObject['severity'] != null
795+
? HarmSeverity._parseValue(jsonObject['severity'])
796+
: null,
797+
severityScore: jsonObject['severityScore'] as double?);
804798
}
805799

806800
CitationMetadata _parseCitationMetadata(Object? jsonObject) {

0 commit comments

Comments
 (0)