RealtimeToolChoice.fromJson constructor

RealtimeToolChoice.fromJson(
  1. Object json
)

Creates from JSON.

Implementation

factory RealtimeToolChoice.fromJson(Object json) {
  if (json == 'auto') return const RealtimeToolChoiceAuto();
  if (json == 'none') return const RealtimeToolChoiceNone();
  if (json == 'required') return const RealtimeToolChoiceRequired();
  if (json is Map<String, dynamic>) {
    final type = json['type'] as String?;
    if (type == 'function') {
      final function = json['function'] as Map<String, dynamic>;
      return RealtimeToolChoiceFunction(function['name'] as String);
    }
  }
  throw FormatException('Invalid RealtimeToolChoice: $json');
}