MessageContent.fromJson constructor

MessageContent.fromJson(
  1. Map<String, dynamic> json
)

Creates a MessageContent from JSON.

Implementation

factory MessageContent.fromJson(Map<String, dynamic> json) {
  final type = json['type'] as String;
  return switch (type) {
    'text' => TextMessageContent.fromJson(json),
    'image_url' => ImageUrlMessageContent.fromJson(json),
    'image_file' => ImageFileMessageContent.fromJson(json),
    'refusal' => RefusalMessageContent.fromJson(json),
    _ => throw FormatException('Unknown content type: $type'),
  };
}