Skip to content

Commit 0e56139

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

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

google/cloud/aiplatform/v1beta1/content.proto

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

55+
// Content Part modality
56+
enum Modality {
57+
// Unspecified modality.
58+
MODALITY_UNSPECIFIED = 0;
59+
60+
// Plain text.
61+
TEXT = 1;
62+
63+
// Image.
64+
IMAGE = 2;
65+
66+
// Video.
67+
VIDEO = 3;
68+
69+
// Audio.
70+
AUDIO = 4;
71+
72+
// Document, e.g. PDF.
73+
DOCUMENT = 5;
74+
}
75+
5576
// The base structured datatype containing multi-part content of a message.
5677
//
5778
// A `Content` includes a `role` field designating the producer of the `Content`
@@ -671,3 +692,12 @@ message RetrievalMetadata {
671692
float google_search_dynamic_retrieval_score = 2
672693
[(google.api.field_behavior) = OPTIONAL];
673694
}
695+
696+
// Represents token counting info for a single modality.
697+
message ModalityTokenCount {
698+
// The modality associated with this token count.
699+
Modality modality = 1;
700+
701+
// Number of tokens.
702+
int32 token_count = 2;
703+
}

google/cloud/aiplatform/v1beta1/prediction_service.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ message CountTokensResponse {
730730
// The total number of billable characters counted across all instances from
731731
// the request.
732732
int32 total_billable_characters = 2;
733+
734+
// Output only. List of modalities that were processed in the request input.
735+
repeated ModalityTokenCount prompt_tokens_details = 3
736+
[(google.api.field_behavior) = OUTPUT_ONLY];
733737
}
734738

735739
// Request message for [PredictionService.GenerateContent].
@@ -851,6 +855,19 @@ message GenerateContentResponse {
851855
// content).
852856
int32 cached_content_token_count = 5
853857
[(google.api.field_behavior) = OUTPUT_ONLY];
858+
859+
// Output only. List of modalities that were processed in the request input.
860+
repeated ModalityTokenCount prompt_tokens_details = 9
861+
[(google.api.field_behavior) = OUTPUT_ONLY];
862+
863+
// Output only. List of modalities of the cached content in the request
864+
// input.
865+
repeated ModalityTokenCount cache_tokens_details = 10
866+
[(google.api.field_behavior) = OUTPUT_ONLY];
867+
868+
// Output only. List of modalities that were returned in the response.
869+
repeated ModalityTokenCount candidates_tokens_details = 11
870+
[(google.api.field_behavior) = OUTPUT_ONLY];
854871
}
855872

856873
// Output only. Generated candidates.

0 commit comments

Comments
 (0)