CountTokensRequest.fromJson constructor

CountTokensRequest.fromJson(
  1. Object? j
)

Implementation

factory CountTokensRequest.fromJson(Object? j) {
  final json = j as Map<String, Object?>;
  return CountTokensRequest(
    endpoint: switch (json['endpoint']) {
      null => '',
      Object $1 => decodeString($1),
    },
    model: switch (json['model']) {
      null => '',
      Object $1 => decodeString($1),
    },
    instances: switch (json['instances']) {
      null => [],
      List<Object?> $1 => [for (final i in $1) protobuf.Value.fromJson(i)],
      _ => throw const FormatException('"instances" is not a list'),
    },
    contents: switch (json['contents']) {
      null => [],
      List<Object?> $1 => [for (final i in $1) Content.fromJson(i)],
      _ => throw const FormatException('"contents" is not a list'),
    },
    systemInstruction: switch (json['systemInstruction']) {
      null => null,
      Object $1 => Content.fromJson($1),
    },
    tools: switch (json['tools']) {
      null => [],
      List<Object?> $1 => [for (final i in $1) Tool.fromJson(i)],
      _ => throw const FormatException('"tools" is not a list'),
    },
    generationConfig: switch (json['generationConfig']) {
      null => null,
      Object $1 => GenerationConfig.fromJson($1),
    },
  );
}