Skip to content

Commit 338c6bf

Browse files
committed
Merge branch 'erikeldridge-vertex-api' into erikeldridge-vertex-adapter
2 parents c891a85 + 814a1dc commit 338c6bf

File tree

9 files changed

+70
-75
lines changed

9 files changed

+70
-75
lines changed

common/api-review/vertexai.api.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export interface GenerativeContentBlob {
327327
export class GenerativeModel extends VertexAIModel {
328328
constructor(vertexAI: VertexAI, modelParams: ModelParams, chromeAdapter: ChromeAdapter, requestOptions?: RequestOptions);
329329
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
330+
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
330331
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
331332
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
332333
// (undocumented)
@@ -419,8 +420,8 @@ export enum HarmSeverity {
419420

420421
// @public
421422
export interface HybridParams {
422-
mode?: InferenceMode;
423-
onCloudParams?: ModelParams;
423+
inCloudParams?: ModelParams;
424+
mode: InferenceMode;
424425
onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt;
425426
}
426427

@@ -509,11 +510,7 @@ export interface ImagenSafetySettings {
509510
}
510511

511512
// @public
512-
export enum InferenceMode {
513-
ONLY_ON_CLOUD = "ONLY_ON_CLOUD",
514-
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
515-
PREFER_ON_DEVICE = "PREFER_ON_DEVICE"
516-
}
513+
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
517514

518515
// @public
519516
export interface InlineDataPart {

docs-devsite/vertexai.generativemodel.md

Lines changed: 11 additions & 0 deletions
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

Lines changed: 9 additions & 9 deletions
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,28 @@ export interface HybridParams
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. |
26-
| [onCloudParams](./vertexai.hybridparams.md#hybridparamsoncloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for on-cloud inference. |
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. |
2727
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | AILanguageModelCreateOptionsWithSystemPrompt | Optional. Specifies advanced params for on-device inference. |
2828

29-
## HybridParams.mode
29+
## HybridParams.inCloudParams
3030

31-
Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device.
31+
Optional. Specifies advanced params for in-cloud inference.
3232

3333
<b>Signature:</b>
3434

3535
```typescript
36-
mode?: InferenceMode;
36+
inCloudParams?: ModelParams;
3737
```
3838

39-
## HybridParams.onCloudParams
39+
## HybridParams.mode
4040

41-
Optional. Specifies advanced params for on-cloud inference.
41+
Specifies on-device or in-cloud inference. Defaults to prefer on-device.
4242

4343
<b>Signature:</b>
4444

4545
```typescript
46-
onCloudParams?: ModelParams;
46+
mode: InferenceMode;
4747
```
4848

4949
## HybridParams.onDeviceParams

docs-devsite/vertexai.md

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ 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 <code>[ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface)</code>.<!-- -->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"><code>personGeneration</code></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. |
5958
| [Modality](./vertexai.md#modality) | Content part modality. |
6059
| [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/) |
6160
| [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that <code>[VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class)</code> can have. |
@@ -92,7 +91,7 @@ The Vertex AI in Firebase Web SDK.
9291
| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
9392
| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | |
9493
| [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. |
94+
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. |
9695
| [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. |
9796
| [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. |
9897
| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
@@ -132,6 +131,7 @@ The Vertex AI in Firebase Web SDK.
132131

133132
| Type Alias | Description |
134133
| --- | --- |
134+
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
135135
| [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. |
136136
| [Role](./vertexai.md#role) | Role is the producer of the content. |
137137
| [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. |
@@ -225,6 +225,16 @@ Possible roles.
225225
POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]
226226
```
227227

228+
## InferenceMode
229+
230+
Determines whether inference happens on-device or in-cloud.
231+
232+
<b>Signature:</b>
233+
234+
```typescript
235+
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
236+
```
237+
228238
## Part
229239

230240
Content part - includes text, image/video, or function call/response part types.
@@ -491,24 +501,6 @@ export declare enum ImagenSafetyFilterLevel
491501
| BLOCK\_NONE | <code>&quot;block_none&quot;</code> | <b><i>(Public Preview)</i></b> The least aggressive filtering level; blocks very few sensitive prompts and responses.<!-- -->Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. |
492502
| BLOCK\_ONLY\_HIGH | <code>&quot;block_only_high&quot;</code> | <b><i>(Public Preview)</i></b> Blocks few sensitive prompts and responses. |
493503

494-
## InferenceMode
495-
496-
Determines whether inference happens on-device or on-cloud.
497-
498-
<b>Signature:</b>
499-
500-
```typescript
501-
export declare enum InferenceMode
502-
```
503-
504-
## Enumeration Members
505-
506-
| Member | Value | Description |
507-
| --- | --- | --- |
508-
| ONLY\_ON\_CLOUD | <code>&quot;ONLY_ON_CLOUD&quot;</code> | Exclusively uses the on-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 on-cloud model. |
511-
512504
## Modality
513505

514506
Content part modality.

packages/vertexai/src/api.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
import {
1818
ImagenModelParams,
19-
InferenceMode,
2019
ModelParams,
2120
VertexAIErrorCode
2221
} from './types';
@@ -106,10 +105,18 @@ describe('Top level API', () => {
106105
expect(genModel).to.be.an.instanceOf(GenerativeModel);
107106
expect(genModel.model).to.equal('publishers/google/models/my-model');
108107
});
109-
it('getGenerativeModel with HybridParams sets the model', () => {
108+
it('getGenerativeModel with HybridParams sets a default model', () => {
110109
const genModel = getGenerativeModel(fakeVertexAI, {
111-
mode: InferenceMode.ONLY_ON_CLOUD,
112-
onCloudParams: { model: 'my-model' }
110+
mode: 'only_on_device'
111+
});
112+
expect(genModel.model).to.equal(
113+
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
114+
);
115+
});
116+
it('getGenerativeModel with HybridParams honors a model override', () => {
117+
const genModel = getGenerativeModel(fakeVertexAI, {
118+
mode: 'only_in_cloud',
119+
inCloudParams: { model: 'my-model' }
113120
});
114121
expect(genModel.model).to.equal('publishers/google/models/my-model');
115122
});

packages/vertexai/src/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,24 @@ export function getGenerativeModel(
7777
): GenerativeModel {
7878
// Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
7979
const hybridParams = modelParams as HybridParams;
80-
let onCloudParams: ModelParams;
80+
let inCloudParams: ModelParams;
8181
if (hybridParams.mode) {
82-
onCloudParams = hybridParams.onCloudParams || {
83-
model: 'gemini-2.0-flash-lite'
82+
inCloudParams = hybridParams.inCloudParams || {
83+
model: GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL
8484
};
8585
} else {
86-
onCloudParams = modelParams as ModelParams;
86+
inCloudParams = modelParams as ModelParams;
8787
}
8888

89-
if (!onCloudParams.model) {
89+
if (!inCloudParams.model) {
9090
throw new VertexAIError(
9191
VertexAIErrorCode.NO_MODEL,
9292
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
9393
);
9494
}
9595
return new GenerativeModel(
9696
vertexAI,
97-
onCloudParams,
97+
inCloudParams,
9898
new ChromeAdapter(
9999
window.ai as AI,
100100
hybridParams.mode,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ import { ChromeAdapter } from '../methods/chrome-adapter';
5050
* @public
5151
*/
5252
export class GenerativeModel extends VertexAIModel {
53+
/**
54+
* Defines the name of the default in-cloud model to use for hybrid inference.
55+
*/
56+
static DEFAULT_HYBRID_IN_CLOUD_MODEL = 'gemini-2.0-flash-lite';
5357
generationConfig: GenerationConfig;
5458
safetySettings: SafetySetting[];
5559
requestOptions?: RequestOptions;

packages/vertexai/src/types/enums.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,3 @@ export enum Modality {
240240
*/
241241
DOCUMENT = 'DOCUMENT'
242242
}
243-
244-
/**
245-
* Determines whether inference happens on-device or on-cloud.
246-
* @public
247-
*/
248-
export enum InferenceMode {
249-
/**
250-
* Uses the on-device model if available, or falls back to the on-cloud model.
251-
*/
252-
PREFER_ON_DEVICE = 'PREFER_ON_DEVICE',
253-
254-
/**
255-
* Exclusively uses the on-device model. Throws if one is not available.
256-
*/
257-
ONLY_ON_DEVICE = 'ONLY_ON_DEVICE',
258-
259-
/**
260-
* Exclusively uses the on-cloud model.
261-
*/
262-
ONLY_ON_CLOUD = 'ONLY_ON_CLOUD'
263-
}

packages/vertexai/src/types/requests.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
FunctionCallingMode,
2222
HarmBlockMethod,
2323
HarmBlockThreshold,
24-
HarmCategory,
25-
InferenceMode
24+
HarmCategory
2625
} from './enums';
2726
import { ObjectSchemaInterface, SchemaRequest } from './schema';
2827

@@ -216,20 +215,26 @@ export interface FunctionCallingConfig {
216215
}
217216

218217
/**
219-
* Configures on-device and on-cloud inference.
220-
* @public
218+
* Toggles hybrid inference.
221219
*/
222220
export interface HybridParams {
223221
/**
224-
* Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device.
222+
* Specifies on-device or in-cloud inference. Defaults to prefer on-device.
225223
*/
226-
mode?: InferenceMode;
224+
mode: InferenceMode;
227225
/**
228226
* Optional. Specifies advanced params for on-device inference.
229227
*/
230228
onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt;
231229
/**
232-
* Optional. Specifies advanced params for on-cloud inference.
230+
* Optional. Specifies advanced params for in-cloud inference.
233231
*/
234-
onCloudParams?: ModelParams;
232+
inCloudParams?: ModelParams;
235233
}
234+
/**
235+
* Determines whether inference happens on-device or in-cloud.
236+
*/
237+
export type InferenceMode =
238+
| 'prefer_on_device'
239+
| 'only_on_device'
240+
| 'only_in_cloud';

0 commit comments

Comments
 (0)