Skip to content

Commit

Permalink
fix the optional attributes while parsing SafetyRating (#13452)
Browse files Browse the repository at this point in the history
  • Loading branch information
cynthiajoan authored Oct 1, 2024
1 parent d29dde4 commit 92469fe
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/firebase_vertexai/firebase_vertexai/lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -784,23 +784,17 @@ UsageMetadata _parseUsageMetadata(Object jsonObject) {
}

SafetyRating _parseSafetyRating(Object? jsonObject) {
return switch (jsonObject) {
{
'category': final Object category,
'probability': final Object probability,
'probabilityScore': final double probabilityScore,
'blocked': final bool blocked,
'severity': final Object severity,
'severityScore': final double severityScore?,
} =>
SafetyRating(HarmCategory._parseValue(category),
HarmProbability._parseValue(probability),
probabilityScore: probabilityScore,
isBlocked: blocked,
severity: HarmSeverity._parseValue(severity),
severityScore: severityScore),
_ => throw unhandledFormat('SafetyRating', jsonObject),
};
if (jsonObject is! Map) {
throw unhandledFormat('SafetyRating', jsonObject);
}
return SafetyRating(HarmCategory._parseValue(jsonObject['category']),
HarmProbability._parseValue(jsonObject['probability']),
probabilityScore: jsonObject['probabilityScore'] as double?,
isBlocked: jsonObject['blocked'] as bool?,
severity: jsonObject['severity'] != null
? HarmSeverity._parseValue(jsonObject['severity'])
: null,
severityScore: jsonObject['severityScore'] as double?);
}

CitationMetadata _parseCitationMetadata(Object? jsonObject) {
Expand Down

0 comments on commit 92469fe

Please sign in to comment.