@@ -23,6 +23,7 @@ import { AIService } from './service';
2323import { AI , AIOptions , VertexAI , VertexAIOptions } from './public-types' ;
2424import {
2525 ImagenModelParams ,
26+ HybridParams ,
2627 ModelParams ,
2728 RequestOptions ,
2829 AIErrorCode
@@ -31,6 +32,8 @@ import { AIError } from './errors';
3132import { AIModel , GenerativeModel , ImagenModel } from './models' ;
3233import { encodeInstanceIdentifier } from './helpers' ;
3334import { GoogleAIBackend , VertexAIBackend } from './backend' ;
35+ import { ChromeAdapter } from './methods/chrome-adapter' ;
36+ import { LanguageModel } from './types/language-model' ;
3437
3538export { ChatSession } from './methods/chat-session' ;
3639export * from './requests/schema-builder' ;
@@ -138,16 +141,36 @@ export function getAI(
138141 */
139142export function getGenerativeModel (
140143 ai : AI ,
141- modelParams : ModelParams ,
144+ modelParams : ModelParams | HybridParams ,
142145 requestOptions ?: RequestOptions
143146) : GenerativeModel {
144- if ( ! modelParams . model ) {
147+ // Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
148+ const hybridParams = modelParams as HybridParams ;
149+ let inCloudParams : ModelParams ;
150+ if ( hybridParams . mode ) {
151+ inCloudParams = hybridParams . inCloudParams || {
152+ model : GenerativeModel . DEFAULT_HYBRID_IN_CLOUD_MODEL
153+ } ;
154+ } else {
155+ inCloudParams = modelParams as ModelParams ;
156+ }
157+
158+ if ( ! inCloudParams . model ) {
145159 throw new AIError (
146160 AIErrorCode . NO_MODEL ,
147161 `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
148162 ) ;
149163 }
150- return new GenerativeModel ( ai , modelParams , requestOptions ) ;
164+ return new GenerativeModel (
165+ ai ,
166+ inCloudParams ,
167+ new ChromeAdapter (
168+ window . LanguageModel as LanguageModel ,
169+ hybridParams . mode ,
170+ hybridParams . onDeviceParams
171+ ) ,
172+ requestOptions
173+ ) ;
151174}
152175
153176/**
0 commit comments