Skip to content

Commit c5a317e

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

File tree

9 files changed

+85
-44
lines changed

9 files changed

+85
-44
lines changed

common/api-review/vertexai.api.md

+4-10
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,9 @@ export enum HarmSeverity {
418419

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

@@ -514,11 +511,8 @@ export interface ImagenSafetySettings {
514511

515512
// @public
516513
export enum InferenceMode {
517-
// (undocumented)
518-
ONLY_ON_CLOUD = "ONLY_ON_CLOUD",
519-
// (undocumented)
514+
ONLY_IN_CLOUD = "ONLY_IN_CLOUD",
520515
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
521-
// (undocumented)
522516
PREFER_ON_DEVICE = "PREFER_ON_DEVICE"
523517
}
524518

docs-devsite/vertexai.generativemodel.md

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export declare class GenerativeModel extends VertexAIModel
2929
3030
| Property | Modifiers | Type | Description |
3131
| --- | --- | --- | --- |
32+
| [DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL](./vertexai.generativemodel.md#generativemodeldefault_hybrid_in_cloud_model) | <code>static</code> | string | Defines the name of the default in-cloud model to use for hybrid inference. |
3233
| [generationConfig](./vertexai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | |
3334
| [requestOptions](./vertexai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
3435
| [safetySettings](./vertexai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface)<!-- -->\[\] | |
@@ -63,6 +64,16 @@ constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: Reque
6364
| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | |
6465
| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
6566
67+
## GenerativeModel.DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL
68+
69+
Defines the name of the default in-cloud model to use for hybrid inference.
70+
71+
<b>Signature:</b>
72+
73+
```typescript
74+
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
75+
```
76+
6677
## GenerativeModel.generationConfig
6778
6879
<b>Signature:</b>

docs-devsite/vertexai.hybridparams.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# HybridParams interface
13-
Configures on-device and on-cloud inference.
13+
Toggles hybrid inference.
1414

1515
<b>Signature:</b>
1616

@@ -22,28 +22,34 @@ export interface HybridParams
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | |
26-
| [onCloudParams](./vertexai.hybridparams.md#hybridparamsoncloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | |
27-
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | |
25+
| [inCloudParams](./vertexai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. |
26+
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. |
27+
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | Optional. Specifies advanced params for on-device inference. |
2828

29-
## HybridParams.mode
29+
## HybridParams.inCloudParams
30+
31+
Optional. Specifies advanced params for in-cloud inference.
3032

3133
<b>Signature:</b>
3234

3335
```typescript
34-
mode?: InferenceMode;
36+
inCloudParams?: ModelParams;
3537
```
3638

37-
## HybridParams.onCloudParams
39+
## HybridParams.mode
40+
41+
Specifies on-device or in-cloud inference. Defaults to prefer on-device.
3842

3943
<b>Signature:</b>
4044

4145
```typescript
42-
onCloudParams?: ModelParams;
46+
mode: InferenceMode;
4347
```
4448

4549
## HybridParams.onDeviceParams
4650

51+
Optional. Specifies advanced params for on-device inference.
52+
4753
<b>Signature:</b>
4854

4955
```typescript

docs-devsite/vertexai.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The Vertex AI in Firebase Web SDK.
5555
| [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | <b><i>(Public Preview)</i></b> Aspect ratios for Imagen images.<!-- -->To specify an aspect ratio for generated images, set the <code>aspectRatio</code> property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface)<!-- -->.<!-- -->See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. |
5656
| [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | <b><i>(Public Preview)</i></b> A filter level controlling whether generation of images containing people or faces is allowed.<!-- -->See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a> documentation for more details. |
5757
| [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | <b><i>(Public Preview)</i></b> A filter level controlling how aggressively to filter sensitive content.<!-- -->Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, <code>violence</code>, <code>sexual</code>, <code>derogatory</code>, and <code>toxic</code>). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. |
58-
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or on-cloud. |
58+
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
5959
| [Modality](./vertexai.md#modality) | Content part modality. |
6060
| [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) |
6161
| [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. |
@@ -92,7 +92,7 @@ The Vertex AI in Firebase Web SDK.
9292
| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
9393
| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | |
9494
| [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. |
95-
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Configures on-device and on-cloud inference. |
95+
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. |
9696
| [ImagenGCSImage](./vertexai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.<!-- -->This feature is not available yet. |
9797
| [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | <b><i>(Public Preview)</i></b> Configuration options for generating images with Imagen.<!-- -->See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. |
9898
| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
@@ -493,7 +493,7 @@ export declare enum ImagenSafetyFilterLevel
493493

494494
## InferenceMode
495495

496-
Determines whether inference happens on-device or on-cloud.
496+
Determines whether inference happens on-device or in-cloud.
497497

498498
<b>Signature:</b>
499499

@@ -505,9 +505,9 @@ export declare enum InferenceMode
505505

506506
| Member | Value | Description |
507507
| --- | --- | --- |
508-
| ONLY\_ON\_CLOUD | <code>&quot;ONLY_ON_CLOUD&quot;</code> | |
509-
| ONLY\_ON\_DEVICE | <code>&quot;ONLY_ON_DEVICE&quot;</code> | |
510-
| PREFER\_ON\_DEVICE | <code>&quot;PREFER_ON_DEVICE&quot;</code> | |
508+
| ONLY\_IN\_CLOUD | <code>&quot;ONLY_IN_CLOUD&quot;</code> | Exclusively uses the in-cloud model. |
509+
| ONLY\_ON\_DEVICE | <code>&quot;ONLY_ON_DEVICE&quot;</code> | Exclusively uses the on-device model. Throws if one is not available. |
510+
| PREFER\_ON\_DEVICE | <code>&quot;PREFER_ON_DEVICE&quot;</code> | Uses the on-device model if available, or falls back to the in-cloud model. |
511511

512512
## Modality
513513

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)