|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +import { getAI, getGenerativeModel } from './api'; |
| 18 | +import { expect } from 'chai'; |
| 19 | +import { InferenceMode } from './public-types'; |
| 20 | +import { getFullApp } from '../test-utils/get-fake-firebase-services'; |
| 21 | +import { DEFAULT_HYBRID_IN_CLOUD_MODEL } from './constants'; |
| 22 | +import { factory } from './factory-browser'; |
| 23 | + |
| 24 | +/** |
| 25 | + * Browser-only top level API tests using a factory that provides |
| 26 | + * a ChromeAdapter. |
| 27 | + */ |
| 28 | +describe('Top level API', () => { |
| 29 | + describe('getAI()', () => { |
| 30 | + it('getGenerativeModel with HybridParams sets a default model', () => { |
| 31 | + const ai = getAI(getFullApp({ apiKey: 'key', appId: 'id' }, factory)); |
| 32 | + const genModel = getGenerativeModel(ai, { |
| 33 | + mode: InferenceMode.ONLY_ON_DEVICE |
| 34 | + }); |
| 35 | + expect(genModel.model).to.equal( |
| 36 | + `models/${DEFAULT_HYBRID_IN_CLOUD_MODEL}` |
| 37 | + ); |
| 38 | + }); |
| 39 | + it('getGenerativeModel with HybridParams honors a model override', () => { |
| 40 | + const ai = getAI(getFullApp({ apiKey: 'key', appId: 'id' }, factory)); |
| 41 | + const genModel = getGenerativeModel(ai, { |
| 42 | + mode: InferenceMode.PREFER_ON_DEVICE, |
| 43 | + inCloudParams: { model: 'my-model' } |
| 44 | + }); |
| 45 | + expect(genModel.model).to.equal('models/my-model'); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments