Skip to content

Moving to string type for the inference mode #8941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions common/api-review/vertexai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,7 @@ export interface ImagenSafetySettings {
}

// @public
export enum InferenceMode {
ONLY_IN_CLOUD = "ONLY_IN_CLOUD",
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
PREFER_ON_DEVICE = "PREFER_ON_DEVICE"
}
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';

// @public
export interface InlineDataPart {
Expand Down
30 changes: 11 additions & 19 deletions docs-devsite/vertexai.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ The Vertex AI in Firebase Web SDK.
| [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. |
| [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. |
| [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. |
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
| [Modality](./vertexai.md#modality) | Content part modality. |
| [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/) |
| [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. |
Expand Down Expand Up @@ -132,6 +131,7 @@ The Vertex AI in Firebase Web SDK.

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

## InferenceMode

Determines whether inference happens on-device or in-cloud.

<b>Signature:</b>

```typescript
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
```

## Part

Content part - includes text, image/video, or function call/response part types.
Expand Down Expand Up @@ -491,24 +501,6 @@ export declare enum ImagenSafetyFilterLevel
| 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. |
| BLOCK\_ONLY\_HIGH | <code>&quot;block_only_high&quot;</code> | <b><i>(Public Preview)</i></b> Blocks few sensitive prompts and responses. |

## InferenceMode

Determines whether inference happens on-device or in-cloud.

<b>Signature:</b>

```typescript
export declare enum InferenceMode
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| ONLY\_IN\_CLOUD | <code>&quot;ONLY_IN_CLOUD&quot;</code> | Exclusively uses the in-cloud model. |
| ONLY\_ON\_DEVICE | <code>&quot;ONLY_ON_DEVICE&quot;</code> | Exclusively uses the on-device model. Throws if one is not available. |
| 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. |

## Modality

Content part modality.
Expand Down
11 changes: 3 additions & 8 deletions packages/vertexai/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
ImagenModelParams,
InferenceMode,
ModelParams,
VertexAIErrorCode
} from './types';
import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types';
import { VertexAIError } from './errors';
import { ImagenModel, getGenerativeModel, getImagenModel } from './api';
import { expect } from 'chai';
Expand Down Expand Up @@ -108,15 +103,15 @@ describe('Top level API', () => {
});
it('getGenerativeModel with HybridParams sets a default model', () => {
const genModel = getGenerativeModel(fakeVertexAI, {
mode: InferenceMode.ONLY_ON_DEVICE
mode: 'only_on_device'
});
expect(genModel.model).to.equal(
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
);
});
it('getGenerativeModel with HybridParams honors a model override', () => {
const genModel = getGenerativeModel(fakeVertexAI, {
mode: InferenceMode.ONLY_IN_CLOUD,
mode: 'prefer_on_device',
inCloudParams: { model: 'my-model' }
});
expect(genModel.model).to.equal('publishers/google/models/my-model');
Expand Down
20 changes: 0 additions & 20 deletions packages/vertexai/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,3 @@ export enum Modality {
*/
DOCUMENT = 'DOCUMENT'
}

/**
* Determines whether inference happens on-device or in-cloud.
*/
export enum InferenceMode {
/**
* Uses the on-device model if available, or falls back to the in-cloud model.
*/
PREFER_ON_DEVICE = 'PREFER_ON_DEVICE',

/**
* Exclusively uses the on-device model. Throws if one is not available.
*/
ONLY_ON_DEVICE = 'ONLY_ON_DEVICE',

/**
* Exclusively uses the in-cloud model.
*/
ONLY_IN_CLOUD = 'ONLY_IN_CLOUD'
}
11 changes: 9 additions & 2 deletions packages/vertexai/src/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {
FunctionCallingMode,
HarmBlockMethod,
HarmBlockThreshold,
HarmCategory,
InferenceMode
HarmCategory
} from './enums';
import { ObjectSchemaInterface, SchemaRequest } from './schema';

Expand Down Expand Up @@ -233,3 +232,11 @@ export interface HybridParams {
*/
inCloudParams?: ModelParams;
}

/**
* Determines whether inference happens on-device or in-cloud.
*/
export type InferenceMode =
| 'prefer_on_device'
| 'only_on_device'
| 'only_in_cloud';
Loading