fromJson static method

CreateAnswerRequest? fromJson(
  1. dynamic value
)

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

Implementation

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

    return CreateAnswerRequest(
      model: mapValueOfType<String>(json, r'model')!,
      question: mapValueOfType<String>(json, r'question')!,
      examples: json[r'examples'] is List
        ? (json[r'examples'] as List).map(
            (e) => e == null ? null : (e as List).cast<String>()
          ).toList()
        : null,
      examplesContext: mapValueOfType<String>(json, r'examples_context')!,
      documents: json[r'documents'] is List
          ? (json[r'documents'] as List).cast<String>()
          : const [],
      file: mapValueOfType<String>(json, r'file'),
      searchModel: mapValueOfType<String>(json, r'search_model') ?? 'ada',
      maxRerank: mapValueOfType<int>(json, r'max_rerank') ?? 200,
      temperature: json[r'temperature'] == null
          ? 0
          : num.parse(json[r'temperature'].toString()),
      logprobs: mapValueOfType<int>(json, r'logprobs'),
      maxTokens: mapValueOfType<int>(json, r'max_tokens') ?? 16,
      stop: CreateAnswerRequestStop.fromJson(json[r'stop']),
      n: mapValueOfType<int>(json, r'n') ?? 1,
      logitBias: mapValueOfType<Object>(json, r'logit_bias'),
      returnMetadata: mapValueOfType<bool>(json, r'return_metadata') ?? false,
      returnPrompt: mapValueOfType<bool>(json, r'return_prompt') ?? false,
      expand: Object.listFromJson(json[r'expand']) ?? const [],
      user: mapValueOfType<String>(json, r'user'),
    );
  }
  return null;
}