ResponseContent.fromJson constructor

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

Implementation

factory ResponseContent.fromJson(Map<String, dynamic> json) {
  switch (json['type']) {
    case 'input_text':
      return InputTextContent(text: json['text'] as String);
    case 'input_image':
      return InputImageContent(
        detail: ImageDetail.fromJson(json['detail'] as String),
        imageUrl: json['image_url'] as String?,
        fileId: json['file_id'] as String?,
      );
    case 'input_file':
      return InputFileContent(
        fileId: json['file_id'] as String?,
        fileData: json['file_data'] as String?,
        filename: json['filename'] as String?,
      );
    case 'output_text':
      return OutputTextContent(
        text: json['text'] as String,
        annotations: (json['annotations'] as List).cast<Map<String, dynamic>>().map(Annotation.fromJson).toList(),
        logProbs: (json['log_probs'] as List?)?.cast<Map<String, dynamic>>().map(LogProb.fromJson).toList(),
      );
    case 'refusal':
      return RefusalContent(refusal: json['refusal'] as String);
    default:
      return OtherResponseContent(json);
  }
}