Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/firebase_ai/firebase_ai/lib/firebase_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export 'src/api.dart'
SafetyRating,
SafetySetting,
UsageMetadata,
WebGroundingChunk;
WebGroundingChunk,
ModalityTokenCount;
export 'src/base_model.dart'
show
GenerativeModel,
Expand Down Expand Up @@ -108,10 +109,13 @@ export 'src/live_api.dart'
LiveServerMessage,
LiveServerContent,
LiveServerToolCall,
LiveServerSetupComplete,
Transcription,
LiveServerToolCallCancellation,
LiveServerResponse,
GoingAwayNotice,
Transcription;
ActivityEnd,
ActivityStart;
export 'src/live_session.dart' show LiveSession;
export 'src/schema.dart' show JSONSchema, Schema, SchemaType;
export 'src/server_template/template_chat.dart'
Expand Down
56 changes: 56 additions & 0 deletions packages/firebase_ai/firebase_ai/lib/src/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,42 @@ final class UsageMetadata {
UsageMetadata._({
this.promptTokenCount,
this.candidatesTokenCount,
this.responseTokenCount,
this.cachedContentTokenCount,
this.totalTokenCount,
this.thoughtsTokenCount,
this.toolUsePromptTokenCount,
this.promptTokensDetails,
this.candidatesTokensDetails,
this.responseTokensDetails,
this.cacheTokensDetails,
this.toolUsePromptTokensDetails,
this.cacheTokensDetails,
this.cachedContentTokenCount,
});

/// Number of tokens in the prompt.
///
/// When cachedContent is set, this is still the total effective prompt size
/// meaning this includes the number of tokens in the cached content.
final int? promptTokenCount;

/// Total number of tokens across the generated candidates.
///
/// This field is used in the standard GenerateContent API.
final int? candidatesTokenCount;

/// Total number of tokens across all the generated response candidates.
///
/// This field is used in the Live API and is equivalent to
/// [candidatesTokenCount] in the standard API.
final int? responseTokenCount;

/// Number of tokens in the cached part of the prompt (the cached content).
///
/// This field is available in the Live API.
final int? cachedContentTokenCount;

/// Total token count for the generation request (prompt + candidates).
final int? totalTokenCount;

Expand All @@ -214,8 +234,21 @@ final class UsageMetadata {
final List<ModalityTokenCount>? promptTokensDetails;

/// List of modalities that were returned in the response.
///
/// This field is used in the standard GenerateContent API.
final List<ModalityTokenCount>? candidatesTokensDetails;

/// List of modalities that were returned in the response.
///
/// This field is used in the Live API and is equivalent to
/// [candidatesTokensDetails] in the standard API.
final List<ModalityTokenCount>? responseTokensDetails;

/// List of modalities of the cached content in the request input.
///
/// This field is available in the Live API.
final List<ModalityTokenCount>? cacheTokensDetails;

/// A list of tokens used by tools whose usage was triggered from a prompt,
/// broken down by modality.
final List<ModalityTokenCount>? toolUsePromptTokensDetails;
Expand Down Expand Up @@ -1547,6 +1580,15 @@ UsageMetadata parseUsageMetadata(Object jsonObject) {
candidatesTokenCount,
_ => null,
};
final responseTokenCount = switch (jsonObject) {
{'responseTokenCount': final int responseTokenCount} => responseTokenCount,
_ => null,
};
final cachedContentTokenCount = switch (jsonObject) {
{'cachedContentTokenCount': final int cachedContentTokenCount} =>
cachedContentTokenCount,
_ => null,
};
final totalTokenCount = switch (jsonObject) {
{'totalTokenCount': final int totalTokenCount} => totalTokenCount,
_ => null,
Expand All @@ -1570,6 +1612,16 @@ UsageMetadata parseUsageMetadata(Object jsonObject) {
candidatesTokensDetails.map(_parseModalityTokenCount).toList(),
_ => null,
};
final responseTokensDetails = switch (jsonObject) {
{'responseTokensDetails': final List<Object?> responseTokensDetails} =>
responseTokensDetails.map(_parseModalityTokenCount).toList(),
_ => null,
};
final cacheTokensDetails = switch (jsonObject) {
{'cacheTokensDetails': final List<Object?> cacheTokensDetails} =>
cacheTokensDetails.map(_parseModalityTokenCount).toList(),
_ => null,
};
final toolUsePromptTokensDetails = switch (jsonObject) {
{
'toolUsePromptTokensDetails': final List<Object?>
Expand All @@ -1591,11 +1643,15 @@ UsageMetadata parseUsageMetadata(Object jsonObject) {
return UsageMetadata._(
promptTokenCount: promptTokenCount,
candidatesTokenCount: candidatesTokenCount,
responseTokenCount: responseTokenCount,
cachedContentTokenCount: cachedContentTokenCount,
totalTokenCount: totalTokenCount,
thoughtsTokenCount: thoughtsTokenCount,
toolUsePromptTokenCount: toolUsePromptTokenCount,
promptTokensDetails: promptTokensDetails,
candidatesTokensDetails: candidatesTokensDetails,
responseTokensDetails: responseTokensDetails,
cacheTokensDetails: cacheTokensDetails,
toolUsePromptTokensDetails: toolUsePromptTokensDetails,
cachedContentTokenCount: cachedContentTokenCount,
cacheTokensDetails: cacheTokensDetails,
Expand Down
2 changes: 2 additions & 0 deletions packages/firebase_ai/firebase_ai/lib/src/firebase_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class FirebaseAI extends FirebasePluginPlatform {
LiveGenerationConfig? liveGenerationConfig,
List<Tool>? tools,
Content? systemInstruction,
Map<String, dynamic>? extraConfig,
}) {
return createLiveGenerativeModel(
app: app,
Expand All @@ -204,6 +205,7 @@ class FirebaseAI extends FirebasePluginPlatform {
liveGenerationConfig: liveGenerationConfig,
tools: tools,
systemInstruction: systemInstruction,
extraConfig: extraConfig ?? {},
appCheck: appCheck,
auth: auth,
useLimitedUseAppCheckTokens: useLimitedUseAppCheckTokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class ImagenModel extends BaseApiClientModel {
/// prompt.
/// Note: Keep this API private until future release.
// ignore: unused_element
Future<ImagenGenerationResponse<ImagenGCSImage>> _generateImagesGCS(
Future<ImagenGenerationResponse<ImagenGCSImage>> generateImagesGCS(
String prompt,
String gcsUri,
) =>
Expand Down
Loading
Loading