GenerateContentResponse parseGenerateContentResponse()

in pkgs/google_generative_ai/lib/src/api.dart [581:600]


GenerateContentResponse parseGenerateContentResponse(Object jsonObject) {
  if (jsonObject case {'error': final Object error}) throw parseError(error);
  final candidates = switch (jsonObject) {
    {'candidates': final List<Object?> candidates} =>
      candidates.map(_parseCandidate).toList(),
    _ => <Candidate>[]
  };
  final promptFeedback = switch (jsonObject) {
    {'promptFeedback': final promptFeedback?} =>
      _parsePromptFeedback(promptFeedback),
    _ => null,
  };
  final usageMedata = switch (jsonObject) {
    {'usageMetadata': final usageMetadata?} =>
      _parseUsageMetadata(usageMetadata),
    _ => null,
  };
  return GenerateContentResponse(candidates, promptFeedback,
      usageMetadata: usageMedata);
}