fromJson static method

CreateCompletionRequest? fromJson(
  1. dynamic value
)

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

Implementation

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

    return CreateCompletionRequest(
      model: mapValueOfType<String>(json, r'model')!,
      prompt: CreateCompletionRequestPrompt.fromJson(json[r'prompt']),
      suffix: mapValueOfType<String>(json, r'suffix'),
      maxTokens: mapValueOfType<int>(json, r'max_tokens') ?? 16,
      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()),
      n: mapValueOfType<int>(json, r'n') ?? 1,
      stream: mapValueOfType<bool>(json, r'stream') ?? false,
      logprobs: mapValueOfType<int>(json, r'logprobs'),
      echo: mapValueOfType<bool>(json, r'echo') ?? false,
      stop: CreateCompletionRequestStop.fromJson(json[r'stop']),
      presencePenalty: json[r'presence_penalty'] == null
          ? 0
          : num.parse(json[r'presence_penalty'].toString()),
      frequencyPenalty: json[r'frequency_penalty'] == null
          ? 0
          : num.parse(json[r'frequency_penalty'].toString()),
      bestOf: mapValueOfType<int>(json, r'best_of') ?? 1,
      logitBias: mapValueOfType<Object>(json, r'logit_bias'),
      user: mapValueOfType<String>(json, r'user'),
    );
  }
  return null;
}