1414 * See the License for the specific language governing permissions and
1515 * limitations under the License.
1616 */
17- import { ImagenModelParams , ModelParams , AIErrorCode } from './types' ;
17+ import {
18+ ImagenModelParams ,
19+ ModelParams ,
20+ AIErrorCode ,
21+ InferenceMode
22+ } from './types' ;
1823import { AIError } from './errors' ;
1924import {
2025 getAI ,
@@ -28,12 +33,17 @@ import {
2833 getTemplateImagenModel ,
2934 TemplateImagenModel
3035} from './api' ;
31- import { expect } from 'chai' ;
36+ import { expect , use } from 'chai' ;
37+ import { stub } from 'sinon' ;
3238import { AI } from './public-types' ;
3339import { GenerativeModel } from './models/generative-model' ;
3440import { GoogleAIBackend , VertexAIBackend } from './backend' ;
3541import { getFullApp } from '../test-utils/get-fake-firebase-services' ;
3642import { AI_TYPE } from './constants' ;
43+ import { logger } from './logger' ;
44+ import sinonChai from 'sinon-chai' ;
45+
46+ use ( sinonChai ) ;
3747
3848const fakeAI : AI = {
3949 app : {
@@ -148,6 +158,17 @@ describe('Top level API', () => {
148158 expect ( genModel ) . to . be . an . instanceOf ( GenerativeModel ) ;
149159 expect ( genModel . model ) . to . equal ( 'publishers/google/models/my-model' ) ;
150160 } ) ;
161+ it ( 'getGenerativeModel warns in hybrid mode if top-level params are set' , ( ) => {
162+ const warnStub = stub ( logger , 'warn' ) ;
163+ const genModel = getGenerativeModel ( fakeAI , {
164+ mode : InferenceMode . PREFER_ON_DEVICE ,
165+ generationConfig : { }
166+ } ) ;
167+ expect ( genModel ) . to . be . an . instanceOf ( GenerativeModel ) ;
168+ expect ( warnStub ) . to . be . calledWithMatch ( InferenceMode . PREFER_ON_DEVICE ) ;
169+ expect ( warnStub ) . to . be . calledWithMatch ( 'generationConfig' ) ;
170+ warnStub . restore ( ) ;
171+ } ) ;
151172 it ( 'getImagenModel throws if no model is provided' , ( ) => {
152173 try {
153174 getImagenModel ( fakeAI , { } as ImagenModelParams ) ;
0 commit comments