Skip to content

Commit a63dbe4

Browse files
authored
Merge 78fed95 into dcc62c0
2 parents dcc62c0 + 78fed95 commit a63dbe4

File tree

14 files changed

+172
-18
lines changed

14 files changed

+172
-18
lines changed

common/api-review/vertexai.api.md

Lines changed: 12 additions & 1 deletion
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)
@@ -344,7 +345,7 @@ export class GenerativeModel extends VertexAIModel {
344345
}
345346

346347
// @public
347-
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
348+
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
348349

349350
// @beta
350351
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
@@ -416,6 +417,13 @@ export enum HarmSeverity {
416417
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE"
417418
}
418419

420+
// @public
421+
export interface HybridParams {
422+
inCloudParams?: ModelParams;
423+
mode: InferenceMode;
424+
onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt;
425+
}
426+
419427
// @beta
420428
export enum ImagenAspectRatio {
421429
LANDSCAPE_16x9 = "16:9",
@@ -500,6 +508,9 @@ export interface ImagenSafetySettings {
500508
safetyFilterLevel?: ImagenSafetyFilterLevel;
501509
}
502510

511+
// @public
512+
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
513+
503514
// @public
504515
export interface InlineDataPart {
505516
// (undocumented)

docs-devsite/_toc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ toc:
536536
path: /docs/reference/js/vertexai.groundingattribution.md
537537
- title: GroundingMetadata
538538
path: /docs/reference/js/vertexai.groundingmetadata.md
539+
- title: HybridParams
540+
path: /docs/reference/js/vertexai.hybridparams.md
539541
- title: ImagenGCSImage
540542
path: /docs/reference/js/vertexai.imagengcsimage.md
541543
- title: ImagenGenerationConfig

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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# HybridParams interface
13+
Toggles hybrid inference.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface HybridParams
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
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) | AILanguageModelCreateOptionsWithSystemPrompt | Optional. Specifies advanced params for on-device inference. |
28+
29+
## HybridParams.inCloudParams
30+
31+
Optional. Specifies advanced params for in-cloud inference.
32+
33+
<b>Signature:</b>
34+
35+
```typescript
36+
inCloudParams?: ModelParams;
37+
```
38+
39+
## HybridParams.mode
40+
41+
Specifies on-device or in-cloud inference. Defaults to prefer on-device.
42+
43+
<b>Signature:</b>
44+
45+
```typescript
46+
mode: InferenceMode;
47+
```
48+
49+
## HybridParams.onDeviceParams
50+
51+
Optional. Specifies advanced params for on-device inference.
52+
53+
<b>Signature:</b>
54+
55+
```typescript
56+
onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt;
57+
```

docs-devsite/vertexai.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The Vertex AI in Firebase Web SDK.
1919
| <b>function(app, ...)</b> |
2020
| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a <code>[VertexAI](./vertexai.vertexai.md#vertexai_interface)</code> instance for the given app. |
2121
| <b>function(vertexAI, ...)</b> |
22-
| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3037c9) | Returns a <code>[GenerativeModel](./vertexai.generativemodel.md#generativemodel_class)</code> class with methods for inference and other functionality. |
22+
| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_8dbc150) | Returns a <code>[GenerativeModel](./vertexai.generativemodel.md#generativemodel_class)</code> class with methods for inference and other functionality. |
2323
| [getImagenModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getimagenmodel_812c375) | <b><i>(Public Preview)</i></b> Returns an <code>[ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class)</code> class with methods for using Imagen.<!-- -->Only Imagen 3 models (named <code>imagen-3.0-*</code>) are supported. |
2424

2525
## Classes
@@ -91,6 +91,7 @@ The Vertex AI in Firebase Web SDK.
9191
| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
9292
| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | |
9393
| [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. |
94+
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. |
9495
| [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. |
9596
| [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. |
9697
| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
@@ -99,10 +100,10 @@ The Vertex AI in Firebase Web SDK.
99100
| [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | <b><i>(Public Preview)</i></b> Settings for controlling the aggressiveness of filtering out sensitive content.<!-- -->See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. |
100101
| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
101102
| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
102-
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)</code>. |
103+
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)</code>. |
103104
| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for <code>[ObjectSchema](./vertexai.objectschema.md#objectschema_class)</code> class. |
104105
| [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with <code>blockReason</code> and the relevant <code>safetyRatings</code>. |
105-
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)</code>. |
106+
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)</code>. |
106107
| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
107108
| [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a <code>[GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface)</code> |
108109
| [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. |
@@ -130,6 +131,7 @@ The Vertex AI in Firebase Web SDK.
130131

131132
| Type Alias | Description |
132133
| --- | --- |
134+
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
133135
| [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. |
134136
| [Role](./vertexai.md#role) | Role is the producer of the content. |
135137
| [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. |
@@ -160,22 +162,22 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions
160162

161163
## function(vertexAI, ...)
162164

163-
### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_e3037c9}
165+
### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_8dbc150}
164166

165167
Returns a <code>[GenerativeModel](./vertexai.generativemodel.md#generativemodel_class)</code> class with methods for inference and other functionality.
166168

167169
<b>Signature:</b>
168170

169171
```typescript
170-
export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
172+
export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
171173
```
172174

173175
#### Parameters
174176

175177
| Parameter | Type | Description |
176178
| --- | --- | --- |
177179
| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | |
178-
| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | |
180+
| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) \| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | |
179181
| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
180182

181183
<b>Returns:</b>
@@ -223,6 +225,16 @@ Possible roles.
223225
POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]
224226
```
225227

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+
226238
## Part
227239

228240
Content part - includes text, image/video, or function call/response part types.

docs-devsite/vertexai.modelparams.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# ModelParams interface
13-
Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)</code>.
13+
Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)</code>.
1414

1515
<b>Signature:</b>
1616

docs-devsite/vertexai.requestoptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# RequestOptions interface
13-
Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)</code>.
13+
Params passed to <code>[getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)</code>.
1414

1515
<b>Signature:</b>
1616

packages/vertexai/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"devDependencies": {
5959
"@firebase/app": "0.11.3",
6060
"@rollup/plugin-json": "6.1.0",
61+
"@types/dom-chromium-ai": "0.0.6",
6162
"rollup": "2.79.2",
6263
"rollup-plugin-replace": "2.2.0",
6364
"rollup-plugin-typescript2": "0.36.0",

packages/vertexai/src/api.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ describe('Top level API', () => {
101101
expect(genModel).to.be.an.instanceOf(GenerativeModel);
102102
expect(genModel.model).to.equal('publishers/google/models/my-model');
103103
});
104+
it('getGenerativeModel with HybridParams sets a default model', () => {
105+
const genModel = getGenerativeModel(fakeVertexAI, {
106+
mode: 'only_on_device'
107+
});
108+
expect(genModel.model).to.equal(
109+
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
110+
);
111+
});
112+
it('getGenerativeModel with HybridParams honors a model override', () => {
113+
const genModel = getGenerativeModel(fakeVertexAI, {
114+
mode: 'only_in_cloud',
115+
inCloudParams: { model: 'my-model' }
116+
});
117+
expect(genModel.model).to.equal('publishers/google/models/my-model');
118+
});
104119
it('getImagenModel throws if no model is provided', () => {
105120
try {
106121
getImagenModel(fakeVertexAI, {} as ImagenModelParams);

packages/vertexai/src/api.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { VertexAIService } from './service';
2323
import { VertexAI, VertexAIOptions } from './public-types';
2424
import {
2525
ImagenModelParams,
26+
HybridParams,
2627
ModelParams,
2728
RequestOptions,
2829
VertexAIErrorCode
@@ -70,16 +71,27 @@ export function getVertexAI(
7071
*/
7172
export function getGenerativeModel(
7273
vertexAI: VertexAI,
73-
modelParams: ModelParams,
74+
modelParams: ModelParams | HybridParams,
7475
requestOptions?: RequestOptions
7576
): GenerativeModel {
76-
if (!modelParams.model) {
77+
// Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
78+
const hybridParams = modelParams as HybridParams;
79+
let inCloudParams: ModelParams;
80+
if (hybridParams.mode) {
81+
inCloudParams = hybridParams.inCloudParams || {
82+
model: GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL
83+
};
84+
} else {
85+
inCloudParams = modelParams as ModelParams;
86+
}
87+
88+
if (!inCloudParams.model) {
7789
throw new VertexAIError(
7890
VertexAIErrorCode.NO_MODEL,
7991
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
8092
);
8193
}
82-
return new GenerativeModel(vertexAI, modelParams, requestOptions);
94+
return new GenerativeModel(vertexAI, inCloudParams, requestOptions);
8395
}
8496

8597
/**

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

Lines changed: 4 additions & 0 deletions
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/requests.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,28 @@ export interface FunctionCallingConfig {
213213
mode?: FunctionCallingMode;
214214
allowedFunctionNames?: string[];
215215
}
216+
217+
/**
218+
* Toggles hybrid inference.
219+
*/
220+
export interface HybridParams {
221+
/**
222+
* Specifies on-device or in-cloud inference. Defaults to prefer on-device.
223+
*/
224+
mode: InferenceMode;
225+
/**
226+
* Optional. Specifies advanced params for on-device inference.
227+
*/
228+
onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt;
229+
/**
230+
* Optional. Specifies advanced params for in-cloud inference.
231+
*/
232+
inCloudParams?: ModelParams;
233+
}
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';

repo-scripts/changelog-generator/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"strict": true,
44
"outDir": "dist",
55
"lib": [
6-
"ESNext"
6+
"ESNext",
7+
"dom"
78
],
89
"module": "CommonJS",
910
"moduleResolution": "node",

yarn.lock

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,17 +2938,20 @@
29382938
"@types/node" "*"
29392939

29402940
"@types/cors@^2.8.12":
2941-
version "2.8.17"
2942-
resolved "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz#5d718a5e494a8166f569d986794e49c48b216b2b"
2943-
integrity sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==
2944-
dependencies:
2945-
"@types/node" "*"
2941+
version "2.8.12"
2942+
resolved "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz"
2943+
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==
29462944

29472945
"@types/deep-eql@*":
29482946
version "4.0.2"
29492947
resolved "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz#334311971d3a07121e7eb91b684a605e7eea9cbd"
29502948
integrity sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==
29512949

2950+
2951+
version "0.0.6"
2952+
resolved "https://registry.npmjs.org/@types/dom-chromium-ai/-/dom-chromium-ai-0.0.6.tgz#0c9e5712d8db3d26586cd9f175001b509cd2e514"
2953+
integrity sha512-/jUGe9a3BLzsjjg18Olk/Ul64PZ0P4aw8uNxrXeXVTni5PSxyCfyhHb4UohsXNVByOnwYGzlqUcb3vYKVsG4mg==
2954+
29522955
"@types/eslint-scope@^3.7.7":
29532956
version "3.7.7"
29542957
resolved "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5"

0 commit comments

Comments
 (0)