Skip to content

Commit 94bd803

Browse files
gsiddherikeldridge
andcommitted
Define HybridParams (#8935)
Co-authored-by: Erik Eldridge <[email protected]>
1 parent d84d8e8 commit 94bd803

File tree

10 files changed

+145
-15
lines changed

10 files changed

+145
-15
lines changed

common/api-review/vertexai.api.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class GenerativeModel extends VertexAIModel {
344344
}
345345

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

349349
// @beta
350350
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
@@ -416,6 +416,18 @@ export enum HarmSeverity {
416416
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE"
417417
}
418418

419+
// @public
420+
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)
428+
onDeviceParams?: LanguageModelCreateOptions;
429+
}
430+
419431
// @beta
420432
export enum ImagenAspectRatio {
421433
LANDSCAPE_16x9 = "16:9",
@@ -500,6 +512,16 @@ export interface ImagenSafetySettings {
500512
safetyFilterLevel?: ImagenSafetyFilterLevel;
501513
}
502514

515+
// @public
516+
export enum InferenceMode {
517+
// (undocumented)
518+
ONLY_ON_CLOUD = "ONLY_ON_CLOUD",
519+
// (undocumented)
520+
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
521+
// (undocumented)
522+
PREFER_ON_DEVICE = "PREFER_ON_DEVICE"
523+
}
524+
503525
// @public
504526
export interface InlineDataPart {
505527
// (undocumented)

docs-devsite/_toc.yaml

+2
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.hybridparams.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
Configures on-device and on-cloud inference.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface HybridParams
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
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 | |
28+
29+
## HybridParams.mode
30+
31+
<b>Signature:</b>
32+
33+
```typescript
34+
mode?: InferenceMode;
35+
```
36+
37+
## HybridParams.onCloudParams
38+
39+
<b>Signature:</b>
40+
41+
```typescript
42+
onCloudParams?: ModelParams;
43+
```
44+
45+
## HybridParams.onDeviceParams
46+
47+
<b>Signature:</b>
48+
49+
```typescript
50+
onDeviceParams?: LanguageModelCreateOptions;
51+
```

docs-devsite/vertexai.md

+26-6
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 [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance for the given app. |
2121
| <b>function(vertexAI, ...)</b> |
22-
| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3037c9) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. |
22+
| [getGenerativeModel(vertexAI, onCloudOrHybridParams, requestOptions)](./vertexai.md#getgenerativemodel_202434f) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) 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 [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.<!-- -->Only Imagen 3 models (named <code>imagen-3.0-*</code>) are supported. |
2424

2525
## Classes
@@ -55,6 +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. |
5859
| [Modality](./vertexai.md#modality) | Content part modality. |
5960
| [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/) |
6061
| [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. |
@@ -91,6 +92,7 @@ The Vertex AI in Firebase Web SDK.
9192
| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
9293
| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | |
9394
| [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. |
9496
| [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. |
9597
| [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. |
9698
| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
@@ -99,10 +101,10 @@ The Vertex AI in Firebase Web SDK.
99101
| [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. |
100102
| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
101103
| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
102-
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)<!-- -->. |
104+
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->. |
103105
| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. |
104106
| [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 [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)<!-- -->. |
107+
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->. |
106108
| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
107109
| [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) |
108110
| [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. |
@@ -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, onCloudOrHybridParams, requestOptions) {:#getgenerativemodel_202434f}
164166

165167
Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) 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, onCloudOrHybridParams: 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+
| onCloudOrHybridParams | [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>
@@ -489,6 +491,24 @@ export declare enum ImagenSafetyFilterLevel
489491
| 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. |
490492
| BLOCK\_ONLY\_HIGH | <code>&quot;block_only_high&quot;</code> | <b><i>(Public Preview)</i></b> Blocks few sensitive prompts and responses. |
491493

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> | |
509+
| ONLY\_ON\_DEVICE | <code>&quot;ONLY_ON_DEVICE&quot;</code> | |
510+
| PREFER\_ON\_DEVICE | <code>&quot;PREFER_ON_DEVICE&quot;</code> | |
511+
492512
## Modality
493513

494514
Content part modality.

docs-devsite/vertexai.modelparams.md

+1-1
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 [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)<!-- -->.
13+
Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->.
1414

1515
<b>Signature:</b>
1616

docs-devsite/vertexai.requestoptions.md

+1-1
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 [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9)<!-- -->.
13+
Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->.
1414

1515
<b>Signature:</b>
1616

packages/vertexai/src/api.ts

+15-3
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+
onCloudOrHybridParams: ModelParams | HybridParams,
7475
requestOptions?: RequestOptions
7576
): GenerativeModel {
76-
if (!modelParams.model) {
77+
// Disambiguates onCloudOrHybridParams input.
78+
const hybridParams = onCloudOrHybridParams as HybridParams;
79+
let onCloudParams: ModelParams;
80+
if (hybridParams.mode) {
81+
onCloudParams = hybridParams.onCloudParams || {
82+
model: 'gemini-2.0-flash-lite'
83+
};
84+
} else {
85+
onCloudParams = onCloudOrHybridParams as ModelParams;
86+
}
87+
88+
if (!onCloudParams.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, onCloudParams, requestOptions);
8395
}
8496

8597
/**

packages/vertexai/src/types/enums.ts

+10
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,13 @@ 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+
PREFER_ON_DEVICE = 'PREFER_ON_DEVICE',
250+
ONLY_ON_DEVICE = 'ONLY_ON_DEVICE',
251+
ONLY_ON_CLOUD = 'ONLY_ON_CLOUD'
252+
}

packages/vertexai/src/types/language-model.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ enum Availability {
3838
'downloading',
3939
'available'
4040
}
41-
interface LanguageModelCreateCoreOptions {
41+
export interface LanguageModelCreateCoreOptions {
4242
topK?: number;
4343
temperature?: number;
4444
expectedInputs?: LanguageModelExpectedInput[];
4545
}
46-
interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
46+
export interface LanguageModelCreateOptions
47+
extends LanguageModelCreateCoreOptions {
4748
signal?: AbortSignal;
4849
systemPrompt?: string;
4950
initialPrompts?: LanguageModelInitialPrompts;

packages/vertexai/src/types/requests.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import { TypedSchema } from '../requests/schema-builder';
1919
import { Content, Part } from './content';
20+
import { LanguageModelCreateOptions } from './language-model';
2021
import {
2122
FunctionCallingMode,
2223
HarmBlockMethod,
2324
HarmBlockThreshold,
24-
HarmCategory
25+
HarmCategory,
26+
InferenceMode
2527
} from './enums';
2628
import { ObjectSchemaInterface, SchemaRequest } from './schema';
2729

@@ -213,3 +215,13 @@ export interface FunctionCallingConfig {
213215
mode?: FunctionCallingMode;
214216
allowedFunctionNames?: string[];
215217
}
218+
219+
/**
220+
* Configures on-device and on-cloud inference.
221+
* @public
222+
*/
223+
export interface HybridParams {
224+
mode?: InferenceMode;
225+
onDeviceParams?: LanguageModelCreateOptions;
226+
onCloudParams?: ModelParams;
227+
}

0 commit comments

Comments
 (0)