File tree 5 files changed +63
-7
lines changed
5 files changed +63
-7
lines changed Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ export class GenerativeModel extends VertexAIModel {
344
344
}
345
345
346
346
// @public
347
- export function getGenerativeModel(vertexAI : VertexAI , modelParams : ModelParams , requestOptions ? : RequestOptions ): GenerativeModel ;
347
+ export function getGenerativeModel(vertexAI : VertexAI , onCloudOrHybridParams : ModelParams | HybridParams , requestOptions ? : RequestOptions ): GenerativeModel ;
348
348
349
349
// @beta
350
350
export function getImagenModel(vertexAI : VertexAI , modelParams : ImagenModelParams , requestOptions ? : RequestOptions ): ImagenModel ;
@@ -500,6 +500,28 @@ export interface ImagenSafetySettings {
500
500
safetyFilterLevel? : ImagenSafetyFilterLevel ;
501
501
}
502
502
503
+ // @public
504
+ export interface HybridParams {
505
+ // (undocumented)
506
+ mode? : InferenceMode ;
507
+ // (undocumented)
508
+ onCloudParams? : ModelParams ;
509
+ // Warning: (ae-forgotten-export) The symbol "AILanguageModelCreateOptionsWithSystemPrompt" needs to be exported by the entry point index.d.ts
510
+ //
511
+ // (undocumented)
512
+ onDeviceParams? : AILanguageModelCreateOptionsWithSystemPrompt ;
513
+ }
514
+
515
+ // @public
516
+ export enum InferenceMode {
517
+ // (undocumented)
518
+ ONLY_ON_CLOUD = " ONLY_ON_CLOUD" ,
519
+ // (undocumented)
520
+ ONLY_ON_DEVICE = " ONLY_ON_DEVICE" ,
521
+ // (undocumented)
522
+ PREFER_ON_DEVICE = " PREFER_ON_DEVICE"
523
+ }
524
+
503
525
// @public
504
526
export interface InlineDataPart {
505
527
// (undocumented)
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import { VertexAIService } from './service';
23
23
import { VertexAI , VertexAIOptions } from './public-types' ;
24
24
import {
25
25
ImagenModelParams ,
26
+ HybridParams ,
26
27
ModelParams ,
27
28
RequestOptions ,
28
29
VertexAIErrorCode
@@ -70,16 +71,27 @@ export function getVertexAI(
70
71
*/
71
72
export function getGenerativeModel (
72
73
vertexAI : VertexAI ,
73
- modelParams : ModelParams ,
74
+ onCloudOrHybridParams : ModelParams | HybridParams ,
74
75
requestOptions ?: RequestOptions
75
76
) : GenerativeModel {
76
- if ( ! modelParams . model ) {
77
+ // Disambiguates onCloudOrHybridParams input.
78
+ const hybridParams = onCloudOrHybridParams as HybridParams ;
79
+ let onCloudParams : ModelParams ;
80
+ if ( hybridParams . mode ) {
81
+ onCloudParams = hybridParams . onCloudParams || {
82
+ model : 'gemini-2.0-flash-lite'
83
+ } ;
84
+ } else {
85
+ onCloudParams = onCloudOrHybridParams as ModelParams ;
86
+ }
87
+
88
+ if ( ! onCloudParams . model ) {
77
89
throw new VertexAIError (
78
90
VertexAIErrorCode . NO_MODEL ,
79
91
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
80
92
) ;
81
93
}
82
- return new GenerativeModel ( vertexAI , modelParams , requestOptions ) ;
94
+ return new GenerativeModel ( vertexAI , onCloudParams , requestOptions ) ;
83
95
}
84
96
85
97
/**
Original file line number Diff line number Diff line change @@ -240,3 +240,13 @@ export enum Modality {
240
240
*/
241
241
DOCUMENT = 'DOCUMENT'
242
242
}
243
+
244
+ /**
245
+ * Determines whether inference happens on-device or on-cloud.
246
+ * @public
247
+ */
248
+ export enum InferenceMode {
249
+ PREFER_ON_DEVICE = 'PREFER_ON_DEVICE' ,
250
+ ONLY_ON_DEVICE = 'ONLY_ON_DEVICE' ,
251
+ ONLY_ON_CLOUD = 'ONLY_ON_CLOUD'
252
+ }
Original file line number Diff line number Diff line change @@ -38,12 +38,12 @@ enum Availability {
38
38
'downloading' ,
39
39
'available'
40
40
}
41
- interface LanguageModelCreateCoreOptions {
41
+ export interface LanguageModelCreateCoreOptions {
42
42
topK ?: number ;
43
43
temperature ?: number ;
44
44
expectedInputs ?: LanguageModelExpectedInput [ ] ;
45
45
}
46
- interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
46
+ export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
47
47
signal ?: AbortSignal ;
48
48
systemPrompt ?: string ;
49
49
initialPrompts ?: LanguageModelInitialPrompts ;
Original file line number Diff line number Diff line change 17
17
18
18
import { TypedSchema } from '../requests/schema-builder' ;
19
19
import { Content , Part } from './content' ;
20
+ import { LanguageModelCreateOptions } from './language-model' ;
20
21
import {
21
22
FunctionCallingMode ,
22
23
HarmBlockMethod ,
23
24
HarmBlockThreshold ,
24
- HarmCategory
25
+ HarmCategory ,
26
+ InferenceMode
25
27
} from './enums' ;
26
28
import { ObjectSchemaInterface , SchemaRequest } from './schema' ;
27
29
@@ -213,3 +215,13 @@ export interface FunctionCallingConfig {
213
215
mode ?: FunctionCallingMode ;
214
216
allowedFunctionNames ?: string [ ] ;
215
217
}
218
+
219
+ /**
220
+ * Configures on-device and on-cloud inference.
221
+ * @public
222
+ */
223
+ export interface HybridParams {
224
+ mode ?: InferenceMode ;
225
+ onDeviceParams ?: LanguageModelCreateOptions ;
226
+ onCloudParams ?: ModelParams ;
227
+ }
You can’t perform that action at this time.
0 commit comments