Skip to content

Moving to in-cloud naming #8938

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
14 changes: 4 additions & 10 deletions common/api-review/vertexai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export interface GenerativeContentBlob {
export class GenerativeModel extends VertexAIModel {
constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions);
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
// (undocumented)
Expand Down Expand Up @@ -418,13 +419,9 @@ export enum HarmSeverity {

// @public
export interface HybridParams {
// (undocumented)
mode?: InferenceMode;
// (undocumented)
onCloudParams?: ModelParams;
inCloudParams?: ModelParams;
mode: InferenceMode;
// Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
onDeviceParams?: LanguageModelCreateOptions;
}

Expand Down Expand Up @@ -514,11 +511,8 @@ export interface ImagenSafetySettings {

// @public
export enum InferenceMode {
// (undocumented)
ONLY_ON_CLOUD = "ONLY_ON_CLOUD",
// (undocumented)
ONLY_IN_CLOUD = "ONLY_IN_CLOUD",
ONLY_ON_DEVICE = "ONLY_ON_DEVICE",
// (undocumented)
PREFER_ON_DEVICE = "PREFER_ON_DEVICE"
}

Expand Down
11 changes: 11 additions & 0 deletions docs-devsite/vertexai.generativemodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export declare class GenerativeModel extends VertexAIModel

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [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. |
| [generationConfig](./vertexai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | |
| [requestOptions](./vertexai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
| [safetySettings](./vertexai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface)<!-- -->\[\] | |
Expand Down Expand Up @@ -63,6 +64,16 @@ constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: Reque
| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | |
| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |

## GenerativeModel.DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL

Defines the name of the default in-cloud model to use for hybrid inference.

<b>Signature:</b>

```typescript
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
```

## GenerativeModel.generationConfig

<b>Signature:</b>
Expand Down
22 changes: 14 additions & 8 deletions docs-devsite/vertexai.hybridparams.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# HybridParams interface
Configures on-device and on-cloud inference.
Toggles hybrid inference.

<b>Signature:</b>

Expand All @@ -22,28 +22,34 @@ export interface HybridParams

| Property | Type | Description |
| --- | --- | --- |
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | |
| [onCloudParams](./vertexai.hybridparams.md#hybridparamsoncloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | |
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | |
| [inCloudParams](./vertexai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. |
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. |
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | Optional. Specifies advanced params for on-device inference. |

## HybridParams.mode
## HybridParams.inCloudParams

Optional. Specifies advanced params for in-cloud inference.

<b>Signature:</b>

```typescript
mode?: InferenceMode;
inCloudParams?: ModelParams;
```

## HybridParams.onCloudParams
## HybridParams.mode

Specifies on-device or in-cloud inference. Defaults to prefer on-device.

<b>Signature:</b>

```typescript
onCloudParams?: ModelParams;
mode: InferenceMode;
```

## HybridParams.onDeviceParams

Optional. Specifies advanced params for on-device inference.

<b>Signature:</b>

```typescript
Expand Down
12 changes: 6 additions & 6 deletions docs-devsite/vertexai.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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 on-cloud. |
| [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 @@ -92,7 +92,7 @@ The Vertex AI in Firebase Web SDK.
| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | |
| [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. |
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Configures on-device and on-cloud inference. |
| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. |
| [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. |
| [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. |
| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
Expand Down Expand Up @@ -493,7 +493,7 @@ export declare enum ImagenSafetyFilterLevel

## InferenceMode

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

<b>Signature:</b>

Expand All @@ -505,9 +505,9 @@ export declare enum InferenceMode

| Member | Value | Description |
| --- | --- | --- |
| ONLY\_ON\_CLOUD | <code>&quot;ONLY_ON_CLOUD&quot;</code> | |
| ONLY\_ON\_DEVICE | <code>&quot;ONLY_ON_DEVICE&quot;</code> | |
| PREFER\_ON\_DEVICE | <code>&quot;PREFER_ON_DEVICE&quot;</code> | |
| 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

Expand Down
22 changes: 15 additions & 7 deletions packages/vertexai/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ describe('Top level API', () => {
expect(genModel).to.be.an.instanceOf(GenerativeModel);
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('getGenerativeModel with HybridParams sets a default model', () => {
const genModel = getGenerativeModel(fakeVertexAI, {
mode: InferenceMode.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,
inCloudParams: { model: 'my-model' }
});
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('getImagenModel throws if no model is provided', () => {
try {
getImagenModel(fakeVertexAI, {} as ImagenModelParams);
Expand All @@ -117,13 +132,6 @@ describe('Top level API', () => {
);
}
});
it('getGenerativeModel with HybridParams sets the model', () => {
const genModel = getGenerativeModel(fakeVertexAI, {
mode: InferenceMode.ONLY_ON_CLOUD,
onCloudParams: { model: 'my-model' }
});
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('getImagenModel throws if no apiKey is provided', () => {
const fakeVertexNoApiKey = {
...fakeVertexAI,
Expand Down
12 changes: 6 additions & 6 deletions packages/vertexai/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ export function getGenerativeModel(
): GenerativeModel {
// Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
const hybridParams = modelParams as HybridParams;
let onCloudParams: ModelParams;
let inCloudParams: ModelParams;
if (hybridParams.mode) {
onCloudParams = hybridParams.onCloudParams || {
model: 'gemini-2.0-flash-lite'
inCloudParams = hybridParams.inCloudParams || {
model: GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL
};
} else {
onCloudParams = modelParams as ModelParams;
inCloudParams = modelParams as ModelParams;
}

if (!onCloudParams.model) {
if (!inCloudParams.model) {
throw new VertexAIError(
VertexAIErrorCode.NO_MODEL,
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
);
}
return new GenerativeModel(vertexAI, onCloudParams, requestOptions);
return new GenerativeModel(vertexAI, inCloudParams, requestOptions);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/vertexai/src/models/generative-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ import { VertexAIModel } from './vertexai-model';
* @public
*/
export class GenerativeModel extends VertexAIModel {
/**
* Defines the name of the default in-cloud model to use for hybrid inference.
*/
static DEFAULT_HYBRID_IN_CLOUD_MODEL = 'gemini-2.0-flash-lite';
generationConfig: GenerationConfig;
safetySettings: SafetySetting[];
requestOptions?: RequestOptions;
Expand Down
16 changes: 13 additions & 3 deletions packages/vertexai/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,21 @@ export enum Modality {
}

/**
* Determines whether inference happens on-device or on-cloud.
* @public
* 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',
ONLY_ON_CLOUD = 'ONLY_ON_CLOUD'

/**
* Exclusively uses the in-cloud model.
*/
ONLY_IN_CLOUD = 'ONLY_IN_CLOUD'
}
16 changes: 12 additions & 4 deletions packages/vertexai/src/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,19 @@ export interface FunctionCallingConfig {
}

/**
* Configures on-device and on-cloud inference.
* @public
* Toggles hybrid inference.
*/
export interface HybridParams {
mode?: InferenceMode;
/**
* Specifies on-device or in-cloud inference. Defaults to prefer on-device.
*/
mode: InferenceMode;
/**
* Optional. Specifies advanced params for on-device inference.
*/
onDeviceParams?: LanguageModelCreateOptions;
onCloudParams?: ModelParams;
/**
* Optional. Specifies advanced params for in-cloud inference.
*/
inCloudParams?: ModelParams;
}
Loading