fromJson static method

ModelStat? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static ModelStat? 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 "ModelStat[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "ModelStat[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return ModelStat(
      completionTokens: mapValueOfType<int>(json, r'completionTokens'),
      costCents: mapValueOfType<int>(json, r'costCents'),
      costPct: num.parse('${json[r'costPct']}'),
      errorRate: num.parse('${json[r'errorRate']}'),
      errors: mapValueOfType<int>(json, r'errors'),
      model: mapValueOfType<String>(json, r'model'),
      modelCount: mapValueOfType<int>(json, r'modelCount'),
      p50Ms: num.parse('${json[r'p50Ms']}'),
      p95Ms: num.parse('${json[r'p95Ms']}'),
      p99Ms: num.parse('${json[r'p99Ms']}'),
      promptTokens: mapValueOfType<int>(json, r'promptTokens'),
      provider: mapValueOfType<String>(json, r'provider'),
      requests: mapValueOfType<int>(json, r'requests'),
      totalTokens: mapValueOfType<int>(json, r'totalTokens'),
    );
  }
  return null;
}