fromJson static method

CreateEditRequest? fromJson(
  1. dynamic value
)

Returns a new CreateEditRequest instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static CreateEditRequest? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "CreateEditRequest[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "CreateEditRequest[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CreateEditRequest(
      model: mapValueOfType<String>(json, r'model')!,
      input: mapValueOfType<String>(json, r'input') ?? '',
      instruction: mapValueOfType<String>(json, r'instruction')!,
      n: mapValueOfType<int>(json, r'n') ?? 1,
      temperature: json[r'temperature'] == null
          ? 1
          : num.parse(json[r'temperature'].toString()),
      topP: json[r'top_p'] == null
          ? 1
          : num.parse(json[r'top_p'].toString()),
    );
  }
  return null;
}