Skip to content

Commit 04d2e4d

Browse files
committed
Moving to string type for the inference mode (#8941)
1 parent 49e3947 commit 04d2e4d

File tree

5 files changed

+24
-54
lines changed

5 files changed

+24
-54
lines changed

common/api-review/vertexai.api.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,7 @@ export interface ImagenSafetySettings {
510510
}
511511

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

519515
// @public
520516
export interface InlineDataPart {

docs-devsite/vertexai.md

+11-19
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 [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 in-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 [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. |
@@ -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 in-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\_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. |
511-
512504
## Modality
513505

514506
Content part modality.

packages/vertexai/src/api.test.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import {
18-
ImagenModelParams,
19-
InferenceMode,
20-
ModelParams,
21-
VertexAIErrorCode
22-
} from './types';
17+
import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types';
2318
import { VertexAIError } from './errors';
2419
import { ImagenModel, getGenerativeModel, getImagenModel } from './api';
2520
import { expect } from 'chai';
@@ -108,15 +103,15 @@ describe('Top level API', () => {
108103
});
109104
it('getGenerativeModel with HybridParams sets a default model', () => {
110105
const genModel = getGenerativeModel(fakeVertexAI, {
111-
mode: InferenceMode.ONLY_ON_DEVICE
106+
mode: 'only_on_device'
112107
});
113108
expect(genModel.model).to.equal(
114109
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
115110
);
116111
});
117112
it('getGenerativeModel with HybridParams honors a model override', () => {
118113
const genModel = getGenerativeModel(fakeVertexAI, {
119-
mode: InferenceMode.ONLY_IN_CLOUD,
114+
mode: 'prefer_on_device',
120115
inCloudParams: { model: 'my-model' }
121116
});
122117
expect(genModel.model).to.equal('publishers/google/models/my-model');

packages/vertexai/src/types/enums.ts

-20
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

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import {
2222
FunctionCallingMode,
2323
HarmBlockMethod,
2424
HarmBlockThreshold,
25-
HarmCategory,
26-
InferenceMode
25+
HarmCategory
2726
} from './enums';
2827
import { ObjectSchemaInterface, SchemaRequest } from './schema';
2928

@@ -233,3 +232,11 @@ export interface HybridParams {
233232
*/
234233
inCloudParams?: ModelParams;
235234
}
235+
236+
/**
237+
* Determines whether inference happens on-device or in-cloud.
238+
*/
239+
export type InferenceMode =
240+
| 'prefer_on_device'
241+
| 'only_on_device'
242+
| 'only_in_cloud';

0 commit comments

Comments
 (0)