Skip to content

Commit 46f1eb7

Browse files
erikeldridgegsiddh
authored andcommitted
Define HybridParams
1 parent 8319ae9 commit 46f1eb7

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

common/api-review/vertexai.api.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class GenerativeModel extends VertexAIModel {
344344
}
345345

346346
// @public
347-
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
347+
export function getGenerativeModel(vertexAI: VertexAI, onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
348348

349349
// @beta
350350
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
@@ -500,6 +500,28 @@ export interface ImagenSafetySettings {
500500
safetyFilterLevel?: ImagenSafetyFilterLevel;
501501
}
502502

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+
503525
// @public
504526
export interface InlineDataPart {
505527
// (undocumented)

packages/vertexai/src/api.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { VertexAIService } from './service';
2323
import { VertexAI, VertexAIOptions } from './public-types';
2424
import {
2525
ImagenModelParams,
26+
HybridParams,
2627
ModelParams,
2728
RequestOptions,
2829
VertexAIErrorCode
@@ -70,16 +71,27 @@ export function getVertexAI(
7071
*/
7172
export function getGenerativeModel(
7273
vertexAI: VertexAI,
73-
modelParams: ModelParams,
74+
onCloudOrHybridParams: ModelParams | HybridParams,
7475
requestOptions?: RequestOptions
7576
): 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) {
7789
throw new VertexAIError(
7890
VertexAIErrorCode.NO_MODEL,
7991
`Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`
8092
);
8193
}
82-
return new GenerativeModel(vertexAI, modelParams, requestOptions);
94+
return new GenerativeModel(vertexAI, onCloudParams, requestOptions);
8395
}
8496

8597
/**

packages/vertexai/src/types/enums.ts

+10
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,13 @@ export enum Modality {
240240
*/
241241
DOCUMENT = 'DOCUMENT'
242242
}
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+
}

packages/vertexai/src/types/language-model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ enum Availability {
3838
'downloading',
3939
'available'
4040
}
41-
interface LanguageModelCreateCoreOptions {
41+
export interface LanguageModelCreateCoreOptions {
4242
topK?: number;
4343
temperature?: number;
4444
expectedInputs?: LanguageModelExpectedInput[];
4545
}
46-
interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
46+
export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
4747
signal?: AbortSignal;
4848
systemPrompt?: string;
4949
initialPrompts?: LanguageModelInitialPrompts;

packages/vertexai/src/types/requests.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import { TypedSchema } from '../requests/schema-builder';
1919
import { Content, Part } from './content';
20+
import {LanguageModelCreateOptions} from './language-model';
2021
import {
2122
FunctionCallingMode,
2223
HarmBlockMethod,
2324
HarmBlockThreshold,
24-
HarmCategory
25+
HarmCategory,
26+
InferenceMode
2527
} from './enums';
2628
import { ObjectSchemaInterface, SchemaRequest } from './schema';
2729

@@ -213,3 +215,13 @@ export interface FunctionCallingConfig {
213215
mode?: FunctionCallingMode;
214216
allowedFunctionNames?: string[];
215217
}
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+
}

0 commit comments

Comments
 (0)