@@ -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' ;
@@ -147,16 +150,36 @@ export function getAI(
147150 */
148151export function getGenerativeModel (
149152 ai : AI ,
150- modelParams : ModelParams ,
153+ modelParams : ModelParams | HybridParams ,
151154 requestOptions ?: RequestOptions
152155) : GenerativeModel {
153- if ( ! modelParams . model ) {
156+ // Uses the existence of HybridParams.mode to clarify the type of the modelParams input.
157+ const hybridParams = modelParams as HybridParams ;
158+ let inCloudParams : ModelParams ;
159+ if ( hybridParams . mode ) {
160+ inCloudParams = hybridParams . inCloudParams || {
161+ model : GenerativeModel . DEFAULT_HYBRID_IN_CLOUD_MODEL
162+ } ;
163+ } else {
164+ inCloudParams = modelParams as ModelParams ;
165+ }
166+
167+ if ( ! inCloudParams . model ) {
154168 throw new AIError (
155169 AIErrorCode . NO_MODEL ,
156170 `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
157171 ) ;
158172 }
159- return new GenerativeModel ( ai , modelParams , requestOptions ) ;
173+ return new GenerativeModel (
174+ ai ,
175+ inCloudParams ,
176+ new ChromeAdapter (
177+ window . LanguageModel as LanguageModel ,
178+ hybridParams . mode ,
179+ hybridParams . onDeviceParams
180+ ) ,
181+ requestOptions
182+ ) ;
160183}
161184
162185/**
0 commit comments