Skip to content

Commit 814a1dc

Browse files
committed
Use type for inference mode and update docs
1 parent 559bd13 commit 814a1dc

File tree

7 files changed

+43
-59
lines changed

7 files changed

+43
-59
lines changed

common/api-review/vertexai.api.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,7 @@ export interface ImagenSafetySettings {
509509
}
510510

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

518514
// @public
519515
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: 2 additions & 3 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';
@@ -108,15 +107,15 @@ describe('Top level API', () => {
108107
});
109108
it('getGenerativeModel with HybridParams sets a default model', () => {
110109
const genModel = getGenerativeModel(fakeVertexAI, {
111-
mode: InferenceMode.ONLY_ON_DEVICE
110+
mode: 'only_on_device'
112111
});
113112
expect(genModel.model).to.equal(
114113
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
115114
);
116115
});
117116
it('getGenerativeModel with HybridParams honors a model override', () => {
118117
const genModel = getGenerativeModel(fakeVertexAI, {
119-
mode: InferenceMode.ONLY_IN_CLOUD,
118+
mode: 'only_in_cloud',
120119
inCloudParams: { model: 'my-model' }
121120
});
122121
expect(genModel.model).to.equal('publishers/google/models/my-model');

packages/vertexai/src/types/enums.ts

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

packages/vertexai/src/types/requests.ts

Lines changed: 8 additions & 2 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

@@ -232,3 +231,10 @@ export interface HybridParams {
232231
*/
233232
inCloudParams?: ModelParams;
234233
}
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)