Skip to content

Commit badaa74

Browse files
gsiddherikeldridge
andauthored
Adding smoke test for new hybrid params (#8937)
* Adding smoke test for new hybrid params * Use the existing name of the model params input --------- Co-authored-by: Erik Eldridge <erikeldridge@google.com>
1 parent 96e7dd5 commit badaa74

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

common/api-review/vertexai.api.md

+1-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, onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
347+
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
348348

349349
// @beta
350350
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;

docs-devsite/vertexai.md

+6-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, onCloudOrHybridParams, requestOptions)](./vertexai.md#getgenerativemodel_202434f) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. |
22+
| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_8dbc150) | 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
@@ -101,10 +101,10 @@ The Vertex AI in Firebase Web SDK.
101101
| [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. |
102102
| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
103103
| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
104-
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->. |
104+
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)<!-- -->. |
105105
| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. |
106106
| [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>. |
107-
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_202434f)<!-- -->. |
107+
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150)<!-- -->. |
108108
| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
109109
| [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) |
110110
| [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. |
@@ -162,22 +162,22 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions
162162

163163
## function(vertexAI, ...)
164164

165-
### getGenerativeModel(vertexAI, onCloudOrHybridParams, requestOptions) {:#getgenerativemodel_202434f}
165+
### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_8dbc150}
166166

167167
Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality.
168168

169169
<b>Signature:</b>
170170

171171
```typescript
172-
export declare function getGenerativeModel(vertexAI: VertexAI, onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
172+
export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
173173
```
174174

175175
#### Parameters
176176

177177
| Parameter | Type | Description |
178178
| --- | --- | --- |
179179
| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | |
180-
| onCloudOrHybridParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) \| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | |
180+
| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) \| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | |
181181
| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
182182

183183
<b>Returns:</b>

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

1515
<b>Signature:</b>
1616

packages/vertexai/src/api.test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types';
17+
import {
18+
ImagenModelParams,
19+
InferenceMode,
20+
ModelParams,
21+
VertexAIErrorCode
22+
} from './types';
1823
import { VertexAIError } from './errors';
1924
import { ImagenModel, getGenerativeModel, getImagenModel } from './api';
2025
import { expect } from 'chai';
@@ -112,6 +117,13 @@ describe('Top level API', () => {
112117
);
113118
}
114119
});
120+
it('getGenerativeModel with HybridParams sets the model', () => {
121+
const genModel = getGenerativeModel(fakeVertexAI, {
122+
mode: InferenceMode.ONLY_ON_CLOUD,
123+
onCloudParams: { model: 'my-model' }
124+
});
125+
expect(genModel.model).to.equal('publishers/google/models/my-model');
126+
});
115127
it('getImagenModel throws if no apiKey is provided', () => {
116128
const fakeVertexNoApiKey = {
117129
...fakeVertexAI,

packages/vertexai/src/api.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ export function getVertexAI(
7171
*/
7272
export function getGenerativeModel(
7373
vertexAI: VertexAI,
74-
onCloudOrHybridParams: ModelParams | HybridParams,
74+
modelParams: ModelParams | HybridParams,
7575
requestOptions?: RequestOptions
7676
): GenerativeModel {
77-
// Disambiguates onCloudOrHybridParams input.
78-
const hybridParams = onCloudOrHybridParams as HybridParams;
77+
// Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
78+
const hybridParams = modelParams as HybridParams;
7979
let onCloudParams: ModelParams;
8080
if (hybridParams.mode) {
8181
onCloudParams = hybridParams.onCloudParams || {
8282
model: 'gemini-2.0-flash-lite'
8383
};
8484
} else {
85-
onCloudParams = onCloudOrHybridParams as ModelParams;
85+
onCloudParams = modelParams as ModelParams;
8686
}
8787

8888
if (!onCloudParams.model) {

0 commit comments

Comments
 (0)