Skip to content

Commit 8c62e01

Browse files
Google APIscopybara-github
authored andcommitted
feat: add per-modality token count break downs for GenAI APIs
PiperOrigin-RevId: 719367305
1 parent 9e0f143 commit 8c62e01

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

google/cloud/aiplatform/v1/content.proto

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ enum HarmCategory {
5151
HARM_CATEGORY_CIVIC_INTEGRITY = 5;
5252
}
5353

54+
// Content Part modality
55+
enum Modality {
56+
// Unspecified modality.
57+
MODALITY_UNSPECIFIED = 0;
58+
59+
// Plain text.
60+
TEXT = 1;
61+
62+
// Image.
63+
IMAGE = 2;
64+
65+
// Video.
66+
VIDEO = 3;
67+
68+
// Audio.
69+
AUDIO = 4;
70+
71+
// Document, e.g. PDF.
72+
DOCUMENT = 5;
73+
}
74+
5475
// The base structured datatype containing multi-part content of a message.
5576
//
5677
// A `Content` includes a `role` field designating the producer of the `Content`
@@ -592,3 +613,12 @@ message RetrievalMetadata {
592613
float google_search_dynamic_retrieval_score = 2
593614
[(google.api.field_behavior) = OPTIONAL];
594615
}
616+
617+
// Represents token counting info for a single modality.
618+
message ModalityTokenCount {
619+
// The modality associated with this token count.
620+
Modality modality = 1;
621+
622+
// Number of tokens.
623+
int32 token_count = 2;
624+
}

google/cloud/aiplatform/v1/prediction_service.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ message CountTokensResponse {
668668
// The total number of billable characters counted across all instances from
669669
// the request.
670670
int32 total_billable_characters = 2;
671+
672+
// Output only. List of modalities that were processed in the request input.
673+
repeated ModalityTokenCount prompt_tokens_details = 3
674+
[(google.api.field_behavior) = OUTPUT_ONLY];
671675
}
672676

673677
// Request message for [PredictionService.GenerateContent].
@@ -789,6 +793,19 @@ message GenerateContentResponse {
789793
// content).
790794
int32 cached_content_token_count = 5
791795
[(google.api.field_behavior) = OUTPUT_ONLY];
796+
797+
// Output only. List of modalities that were processed in the request input.
798+
repeated ModalityTokenCount prompt_tokens_details = 9
799+
[(google.api.field_behavior) = OUTPUT_ONLY];
800+
801+
// Output only. List of modalities of the cached content in the request
802+
// input.
803+
repeated ModalityTokenCount cache_tokens_details = 10
804+
[(google.api.field_behavior) = OUTPUT_ONLY];
805+
806+
// Output only. List of modalities that were returned in the response.
807+
repeated ModalityTokenCount candidates_tokens_details = 11
808+
[(google.api.field_behavior) = OUTPUT_ONLY];
792809
}
793810

794811
// Output only. Generated candidates.

0 commit comments

Comments
 (0)