Skip to content

Commit ff62500

Browse files
committed
Move GoogleAI types to single file
1 parent 02600d0 commit ff62500

File tree

15 files changed

+147
-139
lines changed

15 files changed

+147
-139
lines changed

common/api-review/vertexai.api.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ export interface Citation {
125125
endIndex?: number;
126126
// (undocumented)
127127
license?: string;
128-
// (undocumented)
129128
publicationDate?: Date_2;
130129
// (undocumented)
131130
startIndex?: number;
132-
// (undocumented)
133131
title?: string;
134132
// (undocumented)
135133
uri?: string;
@@ -420,6 +418,60 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp
420418
// @public
421419
export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI;
422420

421+
// Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal
422+
//
423+
// @internal (undocumented)
424+
export interface GoogleAICitationMetadata {
425+
// (undocumented)
426+
citationSources: Citation[];
427+
}
428+
429+
// Warning: (ae-internal-missing-underscore) The name "GoogleAICountTokensRequest" should be prefixed with an underscore because the declaration is marked as @internal
430+
//
431+
// @internal (undocumented)
432+
export interface GoogleAICountTokensRequest {
433+
// (undocumented)
434+
generateContentRequest: {
435+
model: string;
436+
contents: Content[];
437+
systemInstruction?: string | Part | Content;
438+
tools?: Tool[];
439+
generationConfig?: GenerationConfig;
440+
};
441+
}
442+
443+
// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentCandidate" should be prefixed with an underscore because the declaration is marked as @internal
444+
//
445+
// @internal (undocumented)
446+
export interface GoogleAIGenerateContentCandidate {
447+
// (undocumented)
448+
citationMetadata?: GoogleAICitationMetadata;
449+
// (undocumented)
450+
content: Content;
451+
// (undocumented)
452+
finishMessage?: string;
453+
// (undocumented)
454+
finishReason?: FinishReason;
455+
// (undocumented)
456+
groundingMetadata?: GroundingMetadata;
457+
// (undocumented)
458+
index: number;
459+
// (undocumented)
460+
safetyRatings?: SafetyRating[];
461+
}
462+
463+
// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentResponse" should be prefixed with an underscore because the declaration is marked as @internal
464+
//
465+
// @internal (undocumented)
466+
export interface GoogleAIGenerateContentResponse {
467+
// (undocumented)
468+
candidates?: GoogleAIGenerateContentCandidate[];
469+
// (undocumented)
470+
promptFeedback?: PromptFeedback;
471+
// (undocumented)
472+
usageMetadata?: UsageMetadata;
473+
}
474+
423475
// @public @deprecated (undocumented)
424476
export interface GroundingAttribution {
425477
// (undocumented)
@@ -653,7 +705,6 @@ export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"];
653705
export interface PromptFeedback {
654706
// (undocumented)
655707
blockReason?: BlockReason;
656-
// (undocumented)
657708
blockReasonMessage?: string;
658709
// (undocumented)
659710
safetyRatings: SafetyRating[];
@@ -684,11 +735,8 @@ export interface SafetyRating {
684735
category: HarmCategory;
685736
// (undocumented)
686737
probability: HarmProbability;
687-
// (undocumented)
688738
probabilityScore: number;
689-
// (undocumented)
690739
severity: HarmSeverity;
691-
// (undocumented)
692740
severityScore: number;
693741
}
694742

packages/vertexai/src/googleAIMappers.test.ts renamed to packages/vertexai/src/googleai-mappers.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
mapGenerateContentRequest,
2525
mapGenerateContentResponse,
2626
mapPromptFeedback
27-
} from './googleAIMappers';
27+
} from './googleai-mappers';
2828
import {
2929
BlockReason,
3030
Content,
@@ -44,7 +44,7 @@ import {
4444
GoogleAIGenerateContentResponse,
4545
GoogleAIGenerateContentCandidate,
4646
GoogleAICountTokensRequest
47-
} from './types/googleAI';
47+
} from './types/googleai';
4848
import { logger } from './logger';
4949
import { AIError } from './errors';
5050
import { getMockResponse } from '../test-utils/mock-response';
@@ -281,7 +281,7 @@ describe('Google AI Mappers', () => {
281281
.undefined; // Not in Google AI
282282
});
283283

284-
it('should add default safety rating properties and warn', () => {
284+
it('should add default safety rating properties', () => {
285285
const candidates: GoogleAIGenerateContentCandidate[] = [
286286
{
287287
index: 0,
@@ -297,9 +297,6 @@ describe('Google AI Mappers', () => {
297297
}
298298
];
299299
const mapped = mapGenerateContentCandidates(candidates);
300-
expect(loggerWarnStub).to.have.been.calledOnceWith(
301-
"Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values."
302-
);
303300
expect(mapped[0].safetyRatings).to.exist;
304301
const safetyRating = mapped[0].safetyRatings?.[0] as SafetyRating; // Type assertion
305302
expect(safetyRating.severity).to.equal(
@@ -359,7 +356,7 @@ describe('Google AI Mappers', () => {
359356
});
360357

361358
describe('mapPromptFeedback', () => {
362-
it('should add default safety rating properties and warn', () => {
359+
it('should add default safety rating properties', () => {
363360
const feedback: PromptFeedback = {
364361
blockReason: BlockReason.OTHER,
365362
safetyRatings: [
@@ -373,9 +370,6 @@ describe('Google AI Mappers', () => {
373370
// Missing blockReasonMessage
374371
};
375372
const mapped = mapPromptFeedback(feedback);
376-
expect(loggerWarnStub).to.have.been.calledOnceWith(
377-
"PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values."
378-
);
379373
expect(mapped.safetyRatings).to.exist;
380374
const safetyRating = mapped.safetyRatings[0] as SafetyRating; // Type assertion
381375
expect(safetyRating.severity).to.equal(

packages/vertexai/src/googleAIMappers.ts renamed to packages/vertexai/src/googleai-mappers.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
GoogleAIGenerateContentResponse,
3434
GoogleAIGenerateContentCandidate,
3535
GoogleAICountTokensRequest
36-
} from './types/googleAI';
36+
} from './types/googleai';
3737

3838
/**
3939
* This SDK supports both Vertex AI and Google AI APIs.
@@ -159,17 +159,14 @@ export function mapGenerateContentCandidates(
159159
};
160160
}
161161

162-
// Assign missing candidate SafetyRatings properties to their defaults.
162+
// Assign missing candidate SafetyRatings properties to their defaults if undefined.
163163
if (candidate.safetyRatings) {
164-
logger.warn(
165-
"Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values."
166-
);
167164
mappedSafetyRatings = candidate.safetyRatings.map(safetyRating => {
168165
return {
169166
...safetyRating,
170-
severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED,
171-
probabilityScore: 0,
172-
severityScore: 0
167+
severity: safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED,
168+
probabilityScore: safetyRating.probabilityScore ?? 0,
169+
severityScore: safetyRating.severityScore ?? 0
173170
};
174171
});
175172
}
@@ -207,21 +204,18 @@ export function mapGenerateContentCandidates(
207204
export function mapPromptFeedback(
208205
promptFeedback: PromptFeedback
209206
): PromptFeedback {
210-
// Assign missing PromptFeedback SafetyRatings properties to their defaults.
207+
// Assign missing SafetyRating properties to their defaults if undefined.
211208
const mappedSafetyRatings: SafetyRating[] = [];
212209
promptFeedback.safetyRatings.forEach(safetyRating => {
213210
mappedSafetyRatings.push({
214211
category: safetyRating.category,
215212
probability: safetyRating.probability,
216-
severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED,
217-
probabilityScore: 0,
218-
severityScore: 0,
213+
severity: safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED,
214+
probabilityScore: safetyRating.probabilityScore ?? 0,
215+
severityScore: safetyRating.severityScore ?? 0,
219216
blocked: safetyRating.blocked
220217
});
221218
});
222-
logger.warn(
223-
"PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values."
224-
);
225219

226220
const mappedPromptFeedback: PromptFeedback = {
227221
blockReason: promptFeedback.blockReason,

packages/vertexai/src/methods/count-tokens.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { countTokens } from './count-tokens';
2525
import { CountTokensRequest } from '../types';
2626
import { ApiSettings } from '../types/internal';
2727
import { Task } from '../requests/request';
28-
import { mapCountTokensRequest } from '../googleAIMappers';
28+
import { mapCountTokensRequest } from '../googleai-mappers';
2929
import { GoogleAIBackend, VertexAIBackend } from '../backend';
3030

3131
use(sinonChai);

packages/vertexai/src/methods/count-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../types';
2323
import { Task, makeRequest } from '../requests/request';
2424
import { ApiSettings } from '../types/internal';
25-
import * as GoogleAIMapper from '../googleAIMappers';
25+
import * as GoogleAIMapper from '../googleai-mappers';
2626
import { BackendType } from '../public-types';
2727

2828
export async function countTokens(

packages/vertexai/src/methods/generate-content.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { ApiSettings } from '../types/internal';
3333
import { Task } from '../requests/request';
3434
import { AIError } from '../api';
35-
import { mapGenerateContentRequest } from '../googleAIMappers';
35+
import { mapGenerateContentRequest } from '../googleai-mappers';
3636
import { GoogleAIBackend, VertexAIBackend } from '../backend';
3737

3838
use(sinonChai);

packages/vertexai/src/methods/generate-content.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Task, makeRequest } from '../requests/request';
2626
import { createEnhancedContentResponse } from '../requests/response-helpers';
2727
import { processStream } from '../requests/stream-reader';
2828
import { ApiSettings } from '../types/internal';
29-
import * as GoogleAIMapper from '../googleAIMappers';
29+
import * as GoogleAIMapper from '../googleai-mappers';
3030
import { BackendType } from '../public-types';
3131

3232
export async function generateContentStream(
@@ -66,7 +66,7 @@ export async function generateContent(
6666
JSON.stringify(params),
6767
requestOptions
6868
);
69-
const generateContentResponse = await handleGenerateContentResponse(
69+
const generateContentResponse = await processGenerateContentResponse(
7070
response,
7171
apiSettings
7272
);
@@ -78,7 +78,7 @@ export async function generateContent(
7878
};
7979
}
8080

81-
async function handleGenerateContentResponse(
81+
async function processGenerateContentResponse(
8282
response: Response,
8383
apiSettings: ApiSettings
8484
): Promise<GenerateContentResponse> {

packages/vertexai/src/public-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export * from './types';
2323
/**
2424
* An instance of the Firebase AI SDK.
2525
*
26-
* For more information, refer to the documentation for the new {@link AI}.
26+
* For more information, refer to the documentation for the new {@link AI} interface.
2727
*
2828
* @public
2929
*/

packages/vertexai/src/requests/stream-reader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import {
2525
} from '../types';
2626
import { AIError } from '../errors';
2727
import { createEnhancedContentResponse } from './response-helpers';
28-
import * as GoogleAIMapper from '../googleAIMappers';
29-
import { GoogleAIGenerateContentResponse } from '../types/googleAI';
28+
import * as GoogleAIMapper from '../googleai-mappers';
29+
import { GoogleAIGenerateContentResponse } from '../types/googleai';
3030
import { ApiSettings } from '../types/internal';
3131
import { BackendType } from '../public-types';
3232

packages/vertexai/src/types/googleAI/index.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/vertexai/src/types/googleAI/requests.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/vertexai/src/types/googleAI/responses.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)