UsageMetadata.fromJson constructor
UsageMetadata.fromJson(
- Object? j
Implementation
factory UsageMetadata.fromJson(Object? j) {
final json = j as Map<String, Object?>;
return UsageMetadata(
promptTokenCount: switch (json['promptTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
cachedContentTokenCount: switch (json['cachedContentTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
responseTokenCount: switch (json['responseTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
toolUsePromptTokenCount: switch (json['toolUsePromptTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
thoughtsTokenCount: switch (json['thoughtsTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
totalTokenCount: switch (json['totalTokenCount']) {
null => 0,
Object $1 => decodeInt($1),
},
promptTokensDetails: switch (json['promptTokensDetails']) {
null => [],
List<Object?> $1 => [
for (final i in $1) ModalityTokenCount.fromJson(i),
],
_ => throw const FormatException('"promptTokensDetails" is not a list'),
},
cacheTokensDetails: switch (json['cacheTokensDetails']) {
null => [],
List<Object?> $1 => [
for (final i in $1) ModalityTokenCount.fromJson(i),
],
_ => throw const FormatException('"cacheTokensDetails" is not a list'),
},
responseTokensDetails: switch (json['responseTokensDetails']) {
null => [],
List<Object?> $1 => [
for (final i in $1) ModalityTokenCount.fromJson(i),
],
_ => throw const FormatException(
'"responseTokensDetails" is not a list',
),
},
toolUsePromptTokensDetails: switch (json['toolUsePromptTokensDetails']) {
null => [],
List<Object?> $1 => [
for (final i in $1) ModalityTokenCount.fromJson(i),
],
_ => throw const FormatException(
'"toolUsePromptTokensDetails" is not a list',
),
},
);
}