Skip to content

Commit 93154c2

Browse files
erikeldridgegsiddh
authored andcommitted
Moving to in-cloud naming
1 parent badaa74 commit 93154c2

File tree

6 files changed

+54
-28
lines changed

6 files changed

+54
-28
lines changed

common/api-review/vertexai.api.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ export interface GenerativeContentBlob {
326326
export class GenerativeModel extends VertexAIModel {
327327
constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions);
328328
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
329+
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
329330
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
330331
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
331332
// (undocumented)
@@ -418,13 +419,8 @@ export enum HarmSeverity {
418419

419420
// @public
420421
export interface HybridParams {
421-
// (undocumented)
422-
mode?: InferenceMode;
423-
// (undocumented)
424-
onCloudParams?: ModelParams;
425-
// Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
426-
//
427-
// (undocumented)
422+
inCloudParams?: ModelParams;
423+
mode: InferenceMode;
428424
onDeviceParams?: LanguageModelCreateOptions;
429425
}
430426

@@ -515,7 +511,7 @@ export interface ImagenSafetySettings {
515511
// @public
516512
export enum InferenceMode {
517513
// (undocumented)
518-
ONLY_ON_CLOUD = "ONLY_ON_CLOUD",
514+
ONLY_IN_CLOUD = "ONLY_IN_CLOUD",
519515
// (undocumented)
520516
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
521517
// (undocumented)

packages/vertexai/src/api.test.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ describe('Top level API', () => {
106106
expect(genModel).to.be.an.instanceOf(GenerativeModel);
107107
expect(genModel.model).to.equal('publishers/google/models/my-model');
108108
});
109+
it('getGenerativeModel with HybridParams sets a default model', () => {
110+
const genModel = getGenerativeModel(fakeVertexAI, {
111+
mode: InferenceMode.ONLY_ON_DEVICE
112+
});
113+
expect(genModel.model).to.equal(
114+
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
115+
);
116+
});
117+
it('getGenerativeModel with HybridParams honors a model override', () => {
118+
const genModel = getGenerativeModel(fakeVertexAI, {
119+
mode: InferenceMode.ONLY_IN_CLOUD,
120+
inCloudParams: { model: 'my-model' }
121+
});
122+
expect(genModel.model).to.equal('publishers/google/models/my-model');
123+
});
109124
it('getImagenModel throws if no model is provided', () => {
110125
try {
111126
getImagenModel(fakeVertexAI, {} as ImagenModelParams);
@@ -117,13 +132,6 @@ describe('Top level API', () => {
117132
);
118133
}
119134
});
120-
it('getGenerativeModel with HybridParams sets the model', () => {
121-
const genModel = getGenerativeModel(fakeVertexAI, {
122-
mode: InferenceMode.ONLY_ON_CLOUD,
123-
onCloudParams: { model: 'my-model' }
124-
});
125-
expect(genModel.model).to.equal('publishers/google/models/my-model');
126-
});
127135
it('getImagenModel throws if no apiKey is provided', () => {
128136
const fakeVertexNoApiKey = {
129137
...fakeVertexAI,

packages/vertexai/src/api.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ export function getGenerativeModel(
7676
): GenerativeModel {
7777
// Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
7878
const hybridParams = modelParams as HybridParams;
79-
let onCloudParams: ModelParams;
79+
let inCloudParams: ModelParams;
8080
if (hybridParams.mode) {
81-
onCloudParams = hybridParams.onCloudParams || {
82-
model: 'gemini-2.0-flash-lite'
81+
inCloudParams = hybridParams.inCloudParams || {
82+
model: GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL
8383
};
8484
} else {
85-
onCloudParams = modelParams as ModelParams;
85+
inCloudParams = modelParams as ModelParams;
8686
}
8787

88-
if (!onCloudParams.model) {
88+
if (!inCloudParams.model) {
8989
throw new VertexAIError(
9090
VertexAIErrorCode.NO_MODEL,
9191
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
9292
);
9393
}
94-
return new GenerativeModel(vertexAI, onCloudParams, requestOptions);
94+
return new GenerativeModel(vertexAI, inCloudParams, requestOptions);
9595
}
9696

9797
/**

packages/vertexai/src/models/generative-model.ts

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ import { VertexAIModel } from './vertexai-model';
4949
* @public
5050
*/
5151
export class GenerativeModel extends VertexAIModel {
52+
/**
53+
* Defines the name of the default in-cloud model to use for hybrid inference.
54+
*/
55+
static DEFAULT_HYBRID_IN_CLOUD_MODEL = 'gemini-2.0-flash-lite';
5256
generationConfig: GenerationConfig;
5357
safetySettings: SafetySetting[];
5458
requestOptions?: RequestOptions;

packages/vertexai/src/types/enums.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,21 @@ export enum Modality {
242242
}
243243

244244
/**
245-
* Determines whether inference happens on-device or on-cloud.
246-
* @public
245+
* Determines whether inference happens on-device or in-cloud.
247246
*/
248247
export enum InferenceMode {
248+
/**
249+
* Uses the on-device model if available, or falls back to the in-cloud model.
250+
*/
249251
PREFER_ON_DEVICE = 'PREFER_ON_DEVICE',
252+
253+
/**
254+
* Exclusively uses the on-device model. Throws if one is not available.
255+
*/
250256
ONLY_ON_DEVICE = 'ONLY_ON_DEVICE',
251-
ONLY_ON_CLOUD = 'ONLY_ON_CLOUD'
257+
258+
/**
259+
* Exclusively uses the in-cloud model.
260+
*/
261+
ONLY_IN_CLOUD = 'ONLY_IN_CLOUD'
252262
}

packages/vertexai/src/types/requests.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,19 @@ export interface FunctionCallingConfig {
217217
}
218218

219219
/**
220-
* Configures on-device and on-cloud inference.
221-
* @public
220+
* Toggles hybrid inference.
222221
*/
223222
export interface HybridParams {
224-
mode?: InferenceMode;
223+
/**
224+
* Specifies on-device or in-cloud inference. Defaults to prefer on-device.
225+
*/
226+
mode: InferenceMode;
227+
/**
228+
* Optional. Specifies advanced params for on-device inference.
229+
*/
225230
onDeviceParams?: LanguageModelCreateOptions;
226-
onCloudParams?: ModelParams;
231+
/**
232+
* Optional. Specifies advanced params for in-cloud inference.
233+
*/
234+
inCloudParams?: ModelParams;
227235
}

0 commit comments

Comments
 (0)