Skip to content

Commit 6efd13a

Browse files
russellwheatleymikehardy
authored andcommitted
types/responses.ts
1 parent 81ab450 commit 6efd13a

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

packages/ai/lib/types/responses.ts

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
*/
1717

1818
import { Content, FunctionCall, InlineDataPart } from './content';
19-
import { BlockReason, FinishReason, HarmCategory, HarmProbability, HarmSeverity } from './enums';
19+
import {
20+
BlockReason,
21+
FinishReason,
22+
HarmCategory,
23+
HarmProbability,
24+
HarmSeverity,
25+
Modality,
26+
} from './enums';
2027

2128
/**
2229
* Result object returned from {@link GenerativeModel.generateContent} call.
@@ -77,14 +84,28 @@ export interface GenerateContentResponse {
7784
}
7885

7986
/**
80-
* Usage metadata about a <code>{@link GenerateContentResponse}</code>.
87+
* Usage metadata about a {@link GenerateContentResponse}.
8188
*
8289
* @public
8390
*/
8491
export interface UsageMetadata {
8592
promptTokenCount: number;
8693
candidatesTokenCount: number;
8794
totalTokenCount: number;
95+
promptTokensDetails?: ModalityTokenCount[];
96+
candidatesTokensDetails?: ModalityTokenCount[];
97+
}
98+
99+
/**
100+
* Represents token counting info for a single modality.
101+
*
102+
* @public
103+
*/
104+
export interface ModalityTokenCount {
105+
/** The modality associated with this token count. */
106+
modality: Modality;
107+
/** The number of tokens counted. */
108+
tokenCount: number;
88109
}
89110

90111
/**
@@ -95,11 +116,16 @@ export interface UsageMetadata {
95116
export interface PromptFeedback {
96117
blockReason?: BlockReason;
97118
safetyRatings: SafetyRating[];
119+
/**
120+
* A human-readable description of the `blockReason`.
121+
*
122+
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
123+
*/
98124
blockReasonMessage?: string;
99125
}
100126

101127
/**
102-
* A candidate returned as part of a <code>{@link GenerateContentResponse}</code>.
128+
* A candidate returned as part of a {@link GenerateContentResponse}.
103129
* @public
104130
*/
105131
export interface GenerateContentCandidate {
@@ -113,7 +139,7 @@ export interface GenerateContentCandidate {
113139
}
114140

115141
/**
116-
* Citation metadata that may be found on a <code>{@link GenerateContentCandidate}</code>.
142+
* Citation metadata that may be found on a {@link GenerateContentCandidate}.
117143
* @public
118144
*/
119145
export interface CitationMetadata {
@@ -129,7 +155,17 @@ export interface Citation {
129155
endIndex?: number;
130156
uri?: string;
131157
license?: string;
158+
/**
159+
* The title of the cited source, if available.
160+
*
161+
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
162+
*/
132163
title?: string;
164+
/**
165+
* The publication date of the cited source, if available.
166+
*
167+
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
168+
*/
133169
publicationDate?: Date;
134170
}
135171

@@ -140,10 +176,14 @@ export interface Citation {
140176
export interface GroundingMetadata {
141177
webSearchQueries?: string[];
142178
retrievalQueries?: string[];
179+
/**
180+
* @deprecated
181+
*/
143182
groundingAttributions: GroundingAttribution[];
144183
}
145184

146185
/**
186+
* @deprecated
147187
* @public
148188
*/
149189
export interface GroundingAttribution {
@@ -189,14 +229,32 @@ export interface Date {
189229
}
190230

191231
/**
192-
* A safety rating associated with a <code>{@link GenerateContentCandidate}</code>
232+
* A safety rating associated with a {@link GenerateContentCandidate}
193233
* @public
194234
*/
195235
export interface SafetyRating {
196236
category: HarmCategory;
197237
probability: HarmProbability;
238+
/**
239+
* The harm severity level.
240+
*
241+
* This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
242+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`.
243+
*/
198244
severity: HarmSeverity;
245+
/**
246+
* The probability score of the harm category.
247+
*
248+
* This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
249+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
250+
*/
199251
probabilityScore: number;
252+
/**
253+
* The severity score of the harm category.
254+
*
255+
* This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
256+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
257+
*/
200258
severityScore: number;
201259
blocked: boolean;
202260
}
@@ -213,6 +271,13 @@ export interface CountTokensResponse {
213271
/**
214272
* The total number of billable characters counted across all instances
215273
* from the request.
274+
*
275+
* This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
276+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
216277
*/
217278
totalBillableCharacters?: number;
279+
/**
280+
* The breakdown, by modality, of how many tokens are consumed by the prompt.
281+
*/
282+
promptTokensDetails?: ModalityTokenCount[];
218283
}

0 commit comments

Comments
 (0)