From f9faf272b1988a9fca6f75813d8bc31c0fe7b7bc Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Mon, 24 Mar 2025 14:12:35 -0700 Subject: [PATCH 01/16] Define HybridParams --- common/api-review/vertexai.api.md | 24 +++++++++++++++++++++++- packages/vertexai/src/api.ts | 18 +++++++++++++++--- packages/vertexai/src/types/ai.ts | 21 +++++++++++++++++++++ packages/vertexai/src/types/enums.ts | 10 ++++++++++ packages/vertexai/src/types/requests.ts | 14 +++++++++++++- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 packages/vertexai/src/types/ai.ts diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index e7f00c2f4e0..287e2490788 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -344,7 +344,7 @@ export class GenerativeModel extends VertexAIModel { } // @public -export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export function getGenerativeModel(vertexAI: VertexAI, onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel; // @beta export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; @@ -500,6 +500,28 @@ export interface ImagenSafetySettings { safetyFilterLevel?: ImagenSafetyFilterLevel; } +// @public +export interface HybridParams { + // (undocumented) + mode?: InferenceMode; + // (undocumented) + onCloudParams?: ModelParams; + // Warning: (ae-forgotten-export) The symbol "AILanguageModelCreateOptionsWithSystemPrompt" needs to be exported by the entry point index.d.ts + // + // (undocumented) + onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; +} + +// @public +export enum InferenceMode { + // (undocumented) + ONLY_ON_CLOUD = "ONLY_ON_CLOUD", + // (undocumented) + ONLY_ON_DEVICE = "ONLY_ON_DEVICE", + // (undocumented) + PREFER_ON_DEVICE = "PREFER_ON_DEVICE" +} + // @public export interface InlineDataPart { // (undocumented) diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 752e75c7e23..d856549f4dc 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -23,6 +23,7 @@ import { VertexAIService } from './service'; import { VertexAI, VertexAIOptions } from './public-types'; import { ImagenModelParams, + HybridParams, ModelParams, RequestOptions, VertexAIErrorCode @@ -70,16 +71,27 @@ export function getVertexAI( */ export function getGenerativeModel( vertexAI: VertexAI, - modelParams: ModelParams, + onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions ): GenerativeModel { - if (!modelParams.model) { + // Disambiguates onCloudOrHybridParams input. + const hybridParams = onCloudOrHybridParams as HybridParams; + let onCloudParams: ModelParams; + if (hybridParams.mode) { + onCloudParams = hybridParams.onCloudParams || { + model: 'gemini-2.0-flash-lite' + }; + } else { + onCloudParams = onCloudOrHybridParams as ModelParams; + } + + if (!onCloudParams.model) { throw new VertexAIError( VertexAIErrorCode.NO_MODEL, `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })` ); } - return new GenerativeModel(vertexAI, modelParams, requestOptions); + return new GenerativeModel(vertexAI, onCloudParams, requestOptions); } /** diff --git a/packages/vertexai/src/types/ai.ts b/packages/vertexai/src/types/ai.ts new file mode 100644 index 00000000000..30b20863373 --- /dev/null +++ b/packages/vertexai/src/types/ai.ts @@ -0,0 +1,21 @@ +/** + * Shims @types/dom-chromium-ai + * TODO: replace with @types/dom-chromium-ai once we can use es2020.intl. + */ +interface AILanguageModelCreateOptions { + topK?: number; + temperature?: number; +} + +export interface AILanguageModelCreateOptionsWithSystemPrompt + extends AILanguageModelCreateOptions { + systemPrompt?: string; + initialPrompts?: AILanguageModelPrompt[]; +} + +type AILanguageModelPromptRole = 'user' | 'assistant'; + +interface AILanguageModelPrompt { + role: AILanguageModelPromptRole; + content: string; +} diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index a9481d40f5f..1f81ed79a8f 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -240,3 +240,13 @@ export enum Modality { */ DOCUMENT = 'DOCUMENT' } + +/** + * Determines whether inference happens on-device or on-cloud. + * @public + */ +export enum InferenceMode { + PREFER_ON_DEVICE = 'PREFER_ON_DEVICE', + ONLY_ON_DEVICE = 'ONLY_ON_DEVICE', + ONLY_ON_CLOUD = 'ONLY_ON_CLOUD' +} diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 5058b457365..912bcb32a96 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -16,12 +16,14 @@ */ import { TypedSchema } from '../requests/schema-builder'; +import { AILanguageModelCreateOptionsWithSystemPrompt } from './ai'; import { Content, Part } from './content'; import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, - HarmCategory + HarmCategory, + InferenceMode } from './enums'; import { ObjectSchemaInterface, SchemaRequest } from './schema'; @@ -213,3 +215,13 @@ export interface FunctionCallingConfig { mode?: FunctionCallingMode; allowedFunctionNames?: string[]; } + +/** + * Configures on-device and on-cloud inference. + * @public + */ +export interface HybridParams { + mode?: InferenceMode; + onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; + onCloudParams?: ModelParams; +} From 10f99a722da1d60a91f0de6075a97d585f2a4c3a Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Mon, 24 Mar 2025 16:25:35 -0700 Subject: [PATCH 02/16] Copy over most types from @types package --- packages/vertexai/src/types/ai.ts | 378 +++++++++++++++++++++++++++++- 1 file changed, 369 insertions(+), 9 deletions(-) diff --git a/packages/vertexai/src/types/ai.ts b/packages/vertexai/src/types/ai.ts index 30b20863373..86ce44b4d98 100644 --- a/packages/vertexai/src/types/ai.ts +++ b/packages/vertexai/src/types/ai.ts @@ -2,20 +2,380 @@ * Shims @types/dom-chromium-ai * TODO: replace with @types/dom-chromium-ai once we can use es2020.intl. */ +interface AI { + readonly languageModel: AILanguageModelFactory; + readonly summarizer: AISummarizerFactory; + readonly writer: AIWriterFactory; + readonly rewriter: AIRewriterFactory; + readonly translator: AITranslatorFactory; + readonly languageDetector: AILanguageDetectorFactory; +} + +interface AICreateMonitor extends EventTarget { + ondownloadprogress: ((this: AICreateMonitor, ev: DownloadProgressEvent) => any) | null; + + addEventListener( + type: K, + listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, + options?: boolean | AddEventListenerOptions, + ): void; + addEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions, + ): void; + removeEventListener( + type: K, + listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, + options?: boolean | EventListenerOptions, + ): void; + removeEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions, + ): void; +} + +interface DownloadProgressEvent extends Event { + readonly loaded: number; + readonly total: number; +} + +interface AICreateMonitorEventMap { + downloadprogress: DownloadProgressEvent; +} + +type AICreateMonitorCallback = (monitor: AICreateMonitor) => void; + +type AICapabilityAvailability = "readily" | "after-download" | "no"; + +// Language Model +// https://github.com/explainers-by-googlers/prompt-api/#full-api-surface-in-web-idl + +interface AILanguageModelFactory { + create( + options?: AILanguageModelCreateOptionsWithSystemPrompt | AILanguageModelCreateOptionsWithoutSystemPrompt, + ): Promise; + capabilities(): Promise; +} + interface AILanguageModelCreateOptions { - topK?: number; - temperature?: number; + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; + + topK?: number; + temperature?: number; } -export interface AILanguageModelCreateOptionsWithSystemPrompt - extends AILanguageModelCreateOptions { - systemPrompt?: string; - initialPrompts?: AILanguageModelPrompt[]; +export interface AILanguageModelCreateOptionsWithSystemPrompt extends AILanguageModelCreateOptions { + systemPrompt?: string; + initialPrompts?: AILanguageModelPrompt[]; } -type AILanguageModelPromptRole = 'user' | 'assistant'; +interface AILanguageModelCreateOptionsWithoutSystemPrompt extends AILanguageModelCreateOptions { + systemPrompt?: never; + initialPrompts?: + | [AILanguageModelSystemPrompt, ...AILanguageModelPrompt[]] + | AILanguageModelPrompt[]; +} + +type AILanguageModelPromptRole = "user" | "assistant"; +type AILanguageModelInitialPromptRole = "system" | AILanguageModelPromptRole; interface AILanguageModelPrompt { - role: AILanguageModelPromptRole; - content: string; + role: AILanguageModelPromptRole; + content: string; +} + +interface AILanguageModelInitialPrompt { + role: AILanguageModelInitialPromptRole; + content: string; +} + +interface AILanguageModelSystemPrompt extends AILanguageModelInitialPrompt { + role: "system"; +} + +type AILanguageModelPromptInput = string | AILanguageModelPrompt | AILanguageModelPrompt[]; + +interface AILanguageModel extends EventTarget { + prompt(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): Promise; + promptStreaming(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): ReadableStream; + + countPromptTokens(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): Promise; + readonly maxTokens: number; + readonly tokensSoFar: number; + readonly tokensLeft: number; + + readonly topK: number; + readonly temperature: number; + + oncontextoverflow: ((this: AILanguageModel, ev: Event) => any) | null; + + addEventListener( + type: K, + listener: (this: AILanguageModel, ev: AILanguageModelEventMap[K]) => any, + options?: boolean | AddEventListenerOptions, + ): void; + addEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions, + ): void; + removeEventListener( + type: K, + listener: (this: AILanguageModel, ev: AILanguageModelEventMap[K]) => any, + options?: boolean | EventListenerOptions, + ): void; + removeEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions, + ): void; + + clone(options?: AILanguageModelCloneOptions): Promise; + destroy(): void; +} + +interface AILanguageModelEventMap { + contextoverflow: Event; +} + +interface AILanguageModelPromptOptions { + signal?: AbortSignal; +} + +interface AILanguageModelCloneOptions { + signal?: AbortSignal; +} + +interface AILanguageModelCapabilities { + readonly available: AICapabilityAvailability; + languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; + + readonly defaultTopK: number | null; + readonly maxTopK: number | null; + readonly defaultTemperature: number | null; + readonly maxTemperature: number | null; +} + +// Summarizer +// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl + +interface AISummarizerFactory { + create(options?: AISummarizerCreateOptions): Promise; + capabilities(): Promise; +} + +interface AISummarizerCreateOptions { + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; + + sharedContext?: string; + type?: AISummarizerType; + format?: AISummarizerFormat; + length?: AISummarizerLength; +} + +type AISummarizerType = "tl;dr" | "key-points" | "teaser" | "headline"; +type AISummarizerFormat = "plain-text" | "markdown"; +type AISummarizerLength = "short" | "medium" | "long"; + +interface AISummarizer { + summarize(input: string, options?: AISummarizerSummarizeOptions): Promise; + summarizeStreaming(input: string, options?: AISummarizerSummarizeOptions): ReadableStream; + + readonly sharedContext: string; + readonly type: AISummarizerType; + readonly format: AISummarizerFormat; + readonly length: AISummarizerLength; + + destroy(): void; +} + +interface AISummarizerSummarizeOptions { + signal?: AbortSignal; + context?: string; +} + +interface AISummarizerCapabilities { + readonly available: AICapabilityAvailability; + + supportsType(type: AISummarizerType): AICapabilityAvailability; + supportsFormat(format: AISummarizerFormat): AICapabilityAvailability; + supportsLength(length: AISummarizerLength): AICapabilityAvailability; + + languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; +} + +// Writer +// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl + +interface AIWriterFactory { + create(options?: AIWriterCreateOptions): Promise; + capabilities(): Promise; +} + +interface AIWriterCreateOptions { + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; + + sharedContext?: string; + tone?: AIWriterTone; + format?: AIWriterFormat; + length?: AIWriterLength; +} + +type AIWriterTone = "formal" | "neutral" | "casual"; +type AIWriterFormat = "plain-text" | "markdown"; +type AIWriterLength = "short" | "medium" | "long"; + +interface AIWriter { + write(writingTask: string, options?: AIWriterWriteOptions): Promise; + writeStreaming(writingTask: string, options?: AIWriterWriteOptions): ReadableStream; + + readonly sharedContext: string; + readonly tone: AIWriterTone; + readonly format: AIWriterFormat; + readonly length: AIWriterLength; + + destroy(): void; +} + +interface AIWriterWriteOptions { + signal?: AbortSignal; + context?: string; +} + +interface AIWriterCapabilities { + readonly available: AICapabilityAvailability; + + supportsTone(tone: AIWriterTone): AICapabilityAvailability; + supportsFormat(format: AIWriterFormat): AICapabilityAvailability; + supportsLength(length: AIWriterLength): AICapabilityAvailability; + + languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; +} + +// Rewriter +// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl + +interface AIRewriterFactory { + create(options?: AIRewriterCreateOptions): Promise; + capabilities(): Promise; +} + +interface AIRewriterCreateOptions { + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; + + sharedContext?: string; + tone?: AIRewriterTone; + format?: AIRewriterFormat; + length?: AIRewriterLength; +} + +type AIRewriterTone = "as-is" | "more-formal" | "more-casual"; +type AIRewriterFormat = "as-is" | "plain-text" | "markdown"; +type AIRewriterLength = "as-is" | "shorter" | "longer"; + +interface AIRewriter { + rewrite(input: string, options?: AIRewriterRewriteOptions): Promise; + rewriteStreaming(input: string, options?: AIRewriterRewriteOptions): ReadableStream; + + readonly sharedContext: string; + readonly tone: AIRewriterTone; + readonly format: AIRewriterFormat; + readonly length: AIRewriterLength; + + destroy(): void; +} + +interface AIRewriterRewriteOptions { + signal?: AbortSignal; + context?: string; +} + +interface AIRewriterCapabilities { + readonly available: AICapabilityAvailability; + + supportsTone(tone: AIRewriterTone): AICapabilityAvailability; + supportsFormat(format: AIRewriterFormat): AICapabilityAvailability; + supportsLength(length: AIRewriterLength): AICapabilityAvailability; + + languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; } + +// Translator +// https://github.com/WICG/translation-api?tab=readme-ov-file#full-api-surface-in-web-idl + +interface AITranslatorFactory { + create(options: AITranslatorCreateOptions): Promise; + capabilities(): Promise; +} + +interface AITranslator { + translate(input: string, options?: AITranslatorTranslateOptions): Promise; + translateStreaming(input: string, options?: AITranslatorTranslateOptions): ReadableStream; + + readonly sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier; + readonly targetLanguage: Intl.UnicodeBCP47LocaleIdentifier; + + destroy(): void; +} + +interface AITranslatorCapabilities { + readonly available: AICapabilityAvailability; + + languagePairAvailable( + sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier, + targetLanguage: Intl.UnicodeBCP47LocaleIdentifier, + ): AICapabilityAvailability; +} + +interface AITranslatorCreateOptions { + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; + + sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier; + targetLanguage: Intl.UnicodeBCP47LocaleIdentifier; +} + +interface AITranslatorTranslateOptions { + signal?: AbortSignal; +} + +// Language detector +// https://github.com/WICG/translation-api?tab=readme-ov-file#full-api-surface-in-web-idl + +interface AILanguageDetectorFactory { + create(options?: AILanguageDetectorCreateOptions): Promise; + capabilities(): Promise; +} + +interface AILanguageDetector { + detect(input: string, options?: AILanguageDetectorDetectOptions): Promise; + + destroy(): void; +} + +interface AILanguageDetectorCapabilities { + readonly available: AICapabilityAvailability; + + languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; +} + +interface AILanguageDetectorCreateOptions { + signal?: AbortSignal; + monitor?: AICreateMonitorCallback; +} + +interface AILanguageDetectorDetectOptions { + signal?: AbortSignal; +} + +interface LanguageDetectionResult { + /** null represents unknown language */ + detectedLanguage: Intl.UnicodeBCP47LocaleIdentifier | null; + confidence: number; +} \ No newline at end of file From cb88d70a1ac19cd24c85674c141feb5728ccd0a5 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Mon, 24 Mar 2025 16:34:36 -0700 Subject: [PATCH 03/16] Document HybridParams and InferenceMode --- common/api-review/vertexai.api.md | 4 ---- packages/vertexai/src/types/enums.ts | 3 +++ packages/vertexai/src/types/requests.ts | 9 +++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 287e2490788..46d247853a5 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -502,13 +502,9 @@ export interface ImagenSafetySettings { // @public export interface HybridParams { - // (undocumented) mode?: InferenceMode; - // (undocumented) onCloudParams?: ModelParams; // Warning: (ae-forgotten-export) The symbol "AILanguageModelCreateOptionsWithSystemPrompt" needs to be exported by the entry point index.d.ts - // - // (undocumented) onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; } diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index 1f81ed79a8f..f9eddc564f8 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -246,7 +246,10 @@ export enum Modality { * @public */ export enum InferenceMode { + // Specifies the SDK should use on-device if possible, or fall back to on-cloud. PREFER_ON_DEVICE = 'PREFER_ON_DEVICE', + // Specifies the SDK must use on-device or throw. ONLY_ON_DEVICE = 'ONLY_ON_DEVICE', + // Specifies the SDK must use on-cloud. ONLY_ON_CLOUD = 'ONLY_ON_CLOUD' } diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 912bcb32a96..6399af44fb5 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -221,7 +221,16 @@ export interface FunctionCallingConfig { * @public */ export interface HybridParams { + /** + * Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. + */ mode?: InferenceMode; + /** + * Optional. Specifies advanced params for on-device inference + */ onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; + /** + * Optional. Specifies advanced params for on-cloud inference. + */ onCloudParams?: ModelParams; } From 7752cb010e05aa5cbb969a5406de30cd61c05953 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Tue, 25 Mar 2025 09:08:29 -0700 Subject: [PATCH 04/16] Trim unused AI types --- packages/vertexai/src/types/ai.ts | 322 +----------------------------- 1 file changed, 3 insertions(+), 319 deletions(-) diff --git a/packages/vertexai/src/types/ai.ts b/packages/vertexai/src/types/ai.ts index 86ce44b4d98..10cce1cab9b 100644 --- a/packages/vertexai/src/types/ai.ts +++ b/packages/vertexai/src/types/ai.ts @@ -2,20 +2,13 @@ * Shims @types/dom-chromium-ai * TODO: replace with @types/dom-chromium-ai once we can use es2020.intl. */ -interface AI { - readonly languageModel: AILanguageModelFactory; - readonly summarizer: AISummarizerFactory; - readonly writer: AIWriterFactory; - readonly rewriter: AIRewriterFactory; - readonly translator: AITranslatorFactory; - readonly languageDetector: AILanguageDetectorFactory; -} - interface AICreateMonitor extends EventTarget { + // eslint-disable-next-line @typescript-eslint/no-explicit-any ondownloadprogress: ((this: AICreateMonitor, ev: DownloadProgressEvent) => any) | null; addEventListener( type: K, + // eslint-disable-next-line @typescript-eslint/no-explicit-any listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, options?: boolean | AddEventListenerOptions, ): void; @@ -26,6 +19,7 @@ interface AICreateMonitor extends EventTarget { ): void; removeEventListener( type: K, + // eslint-disable-next-line @typescript-eslint/no-explicit-any listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, options?: boolean | EventListenerOptions, ): void; @@ -47,18 +41,9 @@ interface AICreateMonitorEventMap { type AICreateMonitorCallback = (monitor: AICreateMonitor) => void; -type AICapabilityAvailability = "readily" | "after-download" | "no"; - // Language Model // https://github.com/explainers-by-googlers/prompt-api/#full-api-surface-in-web-idl -interface AILanguageModelFactory { - create( - options?: AILanguageModelCreateOptionsWithSystemPrompt | AILanguageModelCreateOptionsWithoutSystemPrompt, - ): Promise; - capabilities(): Promise; -} - interface AILanguageModelCreateOptions { signal?: AbortSignal; monitor?: AICreateMonitorCallback; @@ -72,310 +57,9 @@ export interface AILanguageModelCreateOptionsWithSystemPrompt extends AILanguage initialPrompts?: AILanguageModelPrompt[]; } -interface AILanguageModelCreateOptionsWithoutSystemPrompt extends AILanguageModelCreateOptions { - systemPrompt?: never; - initialPrompts?: - | [AILanguageModelSystemPrompt, ...AILanguageModelPrompt[]] - | AILanguageModelPrompt[]; -} - type AILanguageModelPromptRole = "user" | "assistant"; -type AILanguageModelInitialPromptRole = "system" | AILanguageModelPromptRole; interface AILanguageModelPrompt { role: AILanguageModelPromptRole; content: string; } - -interface AILanguageModelInitialPrompt { - role: AILanguageModelInitialPromptRole; - content: string; -} - -interface AILanguageModelSystemPrompt extends AILanguageModelInitialPrompt { - role: "system"; -} - -type AILanguageModelPromptInput = string | AILanguageModelPrompt | AILanguageModelPrompt[]; - -interface AILanguageModel extends EventTarget { - prompt(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): Promise; - promptStreaming(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): ReadableStream; - - countPromptTokens(input: AILanguageModelPromptInput, options?: AILanguageModelPromptOptions): Promise; - readonly maxTokens: number; - readonly tokensSoFar: number; - readonly tokensLeft: number; - - readonly topK: number; - readonly temperature: number; - - oncontextoverflow: ((this: AILanguageModel, ev: Event) => any) | null; - - addEventListener( - type: K, - listener: (this: AILanguageModel, ev: AILanguageModelEventMap[K]) => any, - options?: boolean | AddEventListenerOptions, - ): void; - addEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions, - ): void; - removeEventListener( - type: K, - listener: (this: AILanguageModel, ev: AILanguageModelEventMap[K]) => any, - options?: boolean | EventListenerOptions, - ): void; - removeEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | EventListenerOptions, - ): void; - - clone(options?: AILanguageModelCloneOptions): Promise; - destroy(): void; -} - -interface AILanguageModelEventMap { - contextoverflow: Event; -} - -interface AILanguageModelPromptOptions { - signal?: AbortSignal; -} - -interface AILanguageModelCloneOptions { - signal?: AbortSignal; -} - -interface AILanguageModelCapabilities { - readonly available: AICapabilityAvailability; - languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; - - readonly defaultTopK: number | null; - readonly maxTopK: number | null; - readonly defaultTemperature: number | null; - readonly maxTemperature: number | null; -} - -// Summarizer -// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl - -interface AISummarizerFactory { - create(options?: AISummarizerCreateOptions): Promise; - capabilities(): Promise; -} - -interface AISummarizerCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; - - sharedContext?: string; - type?: AISummarizerType; - format?: AISummarizerFormat; - length?: AISummarizerLength; -} - -type AISummarizerType = "tl;dr" | "key-points" | "teaser" | "headline"; -type AISummarizerFormat = "plain-text" | "markdown"; -type AISummarizerLength = "short" | "medium" | "long"; - -interface AISummarizer { - summarize(input: string, options?: AISummarizerSummarizeOptions): Promise; - summarizeStreaming(input: string, options?: AISummarizerSummarizeOptions): ReadableStream; - - readonly sharedContext: string; - readonly type: AISummarizerType; - readonly format: AISummarizerFormat; - readonly length: AISummarizerLength; - - destroy(): void; -} - -interface AISummarizerSummarizeOptions { - signal?: AbortSignal; - context?: string; -} - -interface AISummarizerCapabilities { - readonly available: AICapabilityAvailability; - - supportsType(type: AISummarizerType): AICapabilityAvailability; - supportsFormat(format: AISummarizerFormat): AICapabilityAvailability; - supportsLength(length: AISummarizerLength): AICapabilityAvailability; - - languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; -} - -// Writer -// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl - -interface AIWriterFactory { - create(options?: AIWriterCreateOptions): Promise; - capabilities(): Promise; -} - -interface AIWriterCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; - - sharedContext?: string; - tone?: AIWriterTone; - format?: AIWriterFormat; - length?: AIWriterLength; -} - -type AIWriterTone = "formal" | "neutral" | "casual"; -type AIWriterFormat = "plain-text" | "markdown"; -type AIWriterLength = "short" | "medium" | "long"; - -interface AIWriter { - write(writingTask: string, options?: AIWriterWriteOptions): Promise; - writeStreaming(writingTask: string, options?: AIWriterWriteOptions): ReadableStream; - - readonly sharedContext: string; - readonly tone: AIWriterTone; - readonly format: AIWriterFormat; - readonly length: AIWriterLength; - - destroy(): void; -} - -interface AIWriterWriteOptions { - signal?: AbortSignal; - context?: string; -} - -interface AIWriterCapabilities { - readonly available: AICapabilityAvailability; - - supportsTone(tone: AIWriterTone): AICapabilityAvailability; - supportsFormat(format: AIWriterFormat): AICapabilityAvailability; - supportsLength(length: AIWriterLength): AICapabilityAvailability; - - languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; -} - -// Rewriter -// https://github.com/explainers-by-googlers/writing-assistance-apis/#full-api-surface-in-web-idl - -interface AIRewriterFactory { - create(options?: AIRewriterCreateOptions): Promise; - capabilities(): Promise; -} - -interface AIRewriterCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; - - sharedContext?: string; - tone?: AIRewriterTone; - format?: AIRewriterFormat; - length?: AIRewriterLength; -} - -type AIRewriterTone = "as-is" | "more-formal" | "more-casual"; -type AIRewriterFormat = "as-is" | "plain-text" | "markdown"; -type AIRewriterLength = "as-is" | "shorter" | "longer"; - -interface AIRewriter { - rewrite(input: string, options?: AIRewriterRewriteOptions): Promise; - rewriteStreaming(input: string, options?: AIRewriterRewriteOptions): ReadableStream; - - readonly sharedContext: string; - readonly tone: AIRewriterTone; - readonly format: AIRewriterFormat; - readonly length: AIRewriterLength; - - destroy(): void; -} - -interface AIRewriterRewriteOptions { - signal?: AbortSignal; - context?: string; -} - -interface AIRewriterCapabilities { - readonly available: AICapabilityAvailability; - - supportsTone(tone: AIRewriterTone): AICapabilityAvailability; - supportsFormat(format: AIRewriterFormat): AICapabilityAvailability; - supportsLength(length: AIRewriterLength): AICapabilityAvailability; - - languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; -} - -// Translator -// https://github.com/WICG/translation-api?tab=readme-ov-file#full-api-surface-in-web-idl - -interface AITranslatorFactory { - create(options: AITranslatorCreateOptions): Promise; - capabilities(): Promise; -} - -interface AITranslator { - translate(input: string, options?: AITranslatorTranslateOptions): Promise; - translateStreaming(input: string, options?: AITranslatorTranslateOptions): ReadableStream; - - readonly sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier; - readonly targetLanguage: Intl.UnicodeBCP47LocaleIdentifier; - - destroy(): void; -} - -interface AITranslatorCapabilities { - readonly available: AICapabilityAvailability; - - languagePairAvailable( - sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier, - targetLanguage: Intl.UnicodeBCP47LocaleIdentifier, - ): AICapabilityAvailability; -} - -interface AITranslatorCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; - - sourceLanguage: Intl.UnicodeBCP47LocaleIdentifier; - targetLanguage: Intl.UnicodeBCP47LocaleIdentifier; -} - -interface AITranslatorTranslateOptions { - signal?: AbortSignal; -} - -// Language detector -// https://github.com/WICG/translation-api?tab=readme-ov-file#full-api-surface-in-web-idl - -interface AILanguageDetectorFactory { - create(options?: AILanguageDetectorCreateOptions): Promise; - capabilities(): Promise; -} - -interface AILanguageDetector { - detect(input: string, options?: AILanguageDetectorDetectOptions): Promise; - - destroy(): void; -} - -interface AILanguageDetectorCapabilities { - readonly available: AICapabilityAvailability; - - languageAvailable(languageTag: Intl.UnicodeBCP47LocaleIdentifier): AICapabilityAvailability; -} - -interface AILanguageDetectorCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; -} - -interface AILanguageDetectorDetectOptions { - signal?: AbortSignal; -} - -interface LanguageDetectionResult { - /** null represents unknown language */ - detectedLanguage: Intl.UnicodeBCP47LocaleIdentifier | null; - confidence: number; -} \ No newline at end of file From 0d628cfe5dbc7dbe666ae491c91e6ce567744c1d Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Tue, 25 Mar 2025 09:09:10 -0700 Subject: [PATCH 05/16] Assert HybridParams sets the model name --- packages/vertexai/src/api.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 4a0b978d858..bf97facb198 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -14,7 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types'; +import { + ImagenModelParams, + InferenceMode, + ModelParams, + VertexAIErrorCode +} from './types'; import { VertexAIError } from './errors'; import { ImagenModel, getGenerativeModel, getImagenModel } from './api'; import { expect } from 'chai'; @@ -101,6 +106,13 @@ describe('Top level API', () => { expect(genModel).to.be.an.instanceOf(GenerativeModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); + it('getGenerativeModel with HybridParams sets the model', () => { + const genModel = getGenerativeModel(fakeVertexAI, { + mode: InferenceMode.ONLY_ON_CLOUD, + onCloudParams: { model: 'my-model' } + }); + expect(genModel.model).to.equal('publishers/google/models/my-model'); + }); it('getImagenModel throws if no model is provided', () => { try { getImagenModel(fakeVertexAI, {} as ImagenModelParams); From 9302d674d5904c37436d544a3f681f74eec4503c Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Wed, 26 Mar 2025 16:56:42 -0700 Subject: [PATCH 06/16] Use dom-chromium-ai package directly --- packages/vertexai/package.json | 1 + packages/vertexai/src/types/ai.ts | 65 ------------------- packages/vertexai/src/types/requests.ts | 1 - .../changelog-generator/tsconfig.json | 3 +- yarn.lock | 13 ++-- 5 files changed, 11 insertions(+), 72 deletions(-) delete mode 100644 packages/vertexai/src/types/ai.ts diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index 20c21a2bfea..b2ffdcc12c8 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -58,6 +58,7 @@ "devDependencies": { "@firebase/app": "0.11.3", "@rollup/plugin-json": "6.1.0", + "@types/dom-chromium-ai": "0.0.6", "rollup": "2.79.2", "rollup-plugin-replace": "2.2.0", "rollup-plugin-typescript2": "0.36.0", diff --git a/packages/vertexai/src/types/ai.ts b/packages/vertexai/src/types/ai.ts deleted file mode 100644 index 10cce1cab9b..00000000000 --- a/packages/vertexai/src/types/ai.ts +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Shims @types/dom-chromium-ai - * TODO: replace with @types/dom-chromium-ai once we can use es2020.intl. - */ -interface AICreateMonitor extends EventTarget { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ondownloadprogress: ((this: AICreateMonitor, ev: DownloadProgressEvent) => any) | null; - - addEventListener( - type: K, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, - options?: boolean | AddEventListenerOptions, - ): void; - addEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions, - ): void; - removeEventListener( - type: K, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - listener: (this: AICreateMonitor, ev: AICreateMonitorEventMap[K]) => any, - options?: boolean | EventListenerOptions, - ): void; - removeEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | EventListenerOptions, - ): void; -} - -interface DownloadProgressEvent extends Event { - readonly loaded: number; - readonly total: number; -} - -interface AICreateMonitorEventMap { - downloadprogress: DownloadProgressEvent; -} - -type AICreateMonitorCallback = (monitor: AICreateMonitor) => void; - -// Language Model -// https://github.com/explainers-by-googlers/prompt-api/#full-api-surface-in-web-idl - -interface AILanguageModelCreateOptions { - signal?: AbortSignal; - monitor?: AICreateMonitorCallback; - - topK?: number; - temperature?: number; -} - -export interface AILanguageModelCreateOptionsWithSystemPrompt extends AILanguageModelCreateOptions { - systemPrompt?: string; - initialPrompts?: AILanguageModelPrompt[]; -} - -type AILanguageModelPromptRole = "user" | "assistant"; - -interface AILanguageModelPrompt { - role: AILanguageModelPromptRole; - content: string; -} diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 6399af44fb5..dd3e689944b 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -16,7 +16,6 @@ */ import { TypedSchema } from '../requests/schema-builder'; -import { AILanguageModelCreateOptionsWithSystemPrompt } from './ai'; import { Content, Part } from './content'; import { FunctionCallingMode, diff --git a/repo-scripts/changelog-generator/tsconfig.json b/repo-scripts/changelog-generator/tsconfig.json index 38bdb7035e4..cffe622284d 100644 --- a/repo-scripts/changelog-generator/tsconfig.json +++ b/repo-scripts/changelog-generator/tsconfig.json @@ -3,7 +3,8 @@ "strict": true, "outDir": "dist", "lib": [ - "ESNext" + "ESNext", + "dom" ], "module": "CommonJS", "moduleResolution": "node", diff --git a/yarn.lock b/yarn.lock index 5e5947884f9..2160db00a05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2938,17 +2938,20 @@ "@types/node" "*" "@types/cors@^2.8.12": - version "2.8.17" - resolved "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz#5d718a5e494a8166f569d986794e49c48b216b2b" - integrity sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA== - dependencies: - "@types/node" "*" + version "2.8.12" + resolved "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz" + integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw== "@types/deep-eql@*": version "4.0.2" resolved "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz#334311971d3a07121e7eb91b684a605e7eea9cbd" integrity sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw== +"@types/dom-chromium-ai@0.0.6": + version "0.0.6" + resolved "https://registry.npmjs.org/@types/dom-chromium-ai/-/dom-chromium-ai-0.0.6.tgz#0c9e5712d8db3d26586cd9f175001b509cd2e514" + integrity sha512-/jUGe9a3BLzsjjg18Olk/Ul64PZ0P4aw8uNxrXeXVTni5PSxyCfyhHb4UohsXNVByOnwYGzlqUcb3vYKVsG4mg== + "@types/eslint-scope@^3.7.7": version "3.7.7" resolved "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5" From eb6ae3c4894b6f7a369882cd006dc68a3037d472 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Wed, 26 Mar 2025 16:59:32 -0700 Subject: [PATCH 07/16] Use multi-line JSDoc comments for enum --- common/api-review/vertexai.api.md | 4 ---- packages/vertexai/src/types/enums.ts | 14 +++++++++++--- packages/vertexai/src/types/requests.ts | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 46d247853a5..49a690cee02 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -504,17 +504,13 @@ export interface ImagenSafetySettings { export interface HybridParams { mode?: InferenceMode; onCloudParams?: ModelParams; - // Warning: (ae-forgotten-export) The symbol "AILanguageModelCreateOptionsWithSystemPrompt" needs to be exported by the entry point index.d.ts onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; } // @public export enum InferenceMode { - // (undocumented) ONLY_ON_CLOUD = "ONLY_ON_CLOUD", - // (undocumented) ONLY_ON_DEVICE = "ONLY_ON_DEVICE", - // (undocumented) PREFER_ON_DEVICE = "PREFER_ON_DEVICE" } diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index f9eddc564f8..0955aebc9cf 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -246,10 +246,18 @@ export enum Modality { * @public */ export enum InferenceMode { - // Specifies the SDK should use on-device if possible, or fall back to on-cloud. + /** + * Uses the on-device model if available, or falls back to the on-cloud model. + */ PREFER_ON_DEVICE = 'PREFER_ON_DEVICE', - // Specifies the SDK must use on-device or throw. + + /** + * Exclusively uses the on-device model. Throws if one is not available. + */ ONLY_ON_DEVICE = 'ONLY_ON_DEVICE', - // Specifies the SDK must use on-cloud. + + /** + * Exclusively uses the on-cloud model. + */ ONLY_ON_CLOUD = 'ONLY_ON_CLOUD' } diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index dd3e689944b..283b79af66c 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -225,7 +225,7 @@ export interface HybridParams { */ mode?: InferenceMode; /** - * Optional. Specifies advanced params for on-device inference + * Optional. Specifies advanced params for on-device inference. */ onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; /** From b4aeabc04c9f8fd659fb72ab3f7490f7dd15d69e Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Thu, 27 Mar 2025 10:33:08 -0700 Subject: [PATCH 08/16] Use the existing name of the model params input --- packages/vertexai/src/api.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index d856549f4dc..60bf9fcb006 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -71,18 +71,18 @@ export function getVertexAI( */ export function getGenerativeModel( vertexAI: VertexAI, - onCloudOrHybridParams: ModelParams | HybridParams, + modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions ): GenerativeModel { - // Disambiguates onCloudOrHybridParams input. - const hybridParams = onCloudOrHybridParams as HybridParams; + // Uses the existence of HybridParams.mode to clarify the type of the modelParams input. + const hybridParams = modelParams as HybridParams; let onCloudParams: ModelParams; if (hybridParams.mode) { onCloudParams = hybridParams.onCloudParams || { model: 'gemini-2.0-flash-lite' }; } else { - onCloudParams = onCloudOrHybridParams as ModelParams; + onCloudParams = modelParams as ModelParams; } if (!onCloudParams.model) { From 2c8915e8bbdbefd745f8c037e87ab426f8fe188e Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Thu, 27 Mar 2025 14:23:38 -0700 Subject: [PATCH 09/16] Run docgen:all --- common/api-review/vertexai.api.md | 16 +++---- docs-devsite/_toc.yaml | 2 + docs-devsite/vertexai.hybridparams.md | 57 +++++++++++++++++++++++++ docs-devsite/vertexai.md | 32 +++++++++++--- docs-devsite/vertexai.modelparams.md | 2 +- docs-devsite/vertexai.requestoptions.md | 2 +- 6 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 docs-devsite/vertexai.hybridparams.md diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 49a690cee02..0af6e07f19e 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -344,7 +344,7 @@ export class GenerativeModel extends VertexAIModel { } // @public -export function getGenerativeModel(vertexAI: VertexAI, onCloudOrHybridParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel; +export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel; // @beta export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; @@ -416,6 +416,13 @@ export enum HarmSeverity { HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE" } +// @public +export interface HybridParams { + mode?: InferenceMode; + onCloudParams?: ModelParams; + onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; +} + // @beta export enum ImagenAspectRatio { LANDSCAPE_16x9 = "16:9", @@ -500,13 +507,6 @@ export interface ImagenSafetySettings { safetyFilterLevel?: ImagenSafetyFilterLevel; } -// @public -export interface HybridParams { - mode?: InferenceMode; - onCloudParams?: ModelParams; - onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; -} - // @public export enum InferenceMode { ONLY_ON_CLOUD = "ONLY_ON_CLOUD", diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index 665222edb9d..64e24534590 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -536,6 +536,8 @@ toc: path: /docs/reference/js/vertexai.groundingattribution.md - title: GroundingMetadata path: /docs/reference/js/vertexai.groundingmetadata.md + - title: HybridParams + path: /docs/reference/js/vertexai.hybridparams.md - title: ImagenGCSImage path: /docs/reference/js/vertexai.imagengcsimage.md - title: ImagenGenerationConfig diff --git a/docs-devsite/vertexai.hybridparams.md b/docs-devsite/vertexai.hybridparams.md new file mode 100644 index 00000000000..9f340babccf --- /dev/null +++ b/docs-devsite/vertexai.hybridparams.md @@ -0,0 +1,57 @@ +Project: /docs/reference/js/_project.yaml +Book: /docs/reference/_book.yaml +page_type: reference + +{% comment %} +DO NOT EDIT THIS FILE! +This is generated by the JS SDK team, and any local changes will be +overwritten. Changes should be made in the source code at +https://github.com/firebase/firebase-js-sdk +{% endcomment %} + +# HybridParams interface +Configures on-device and on-cloud inference. + +Signature: + +```typescript +export interface HybridParams +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. | +| [onCloudParams](./vertexai.hybridparams.md#hybridparamsoncloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for on-cloud inference. | +| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | AILanguageModelCreateOptionsWithSystemPrompt | Optional. Specifies advanced params for on-device inference. | + +## HybridParams.mode + +Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. + +Signature: + +```typescript +mode?: InferenceMode; +``` + +## HybridParams.onCloudParams + +Optional. Specifies advanced params for on-cloud inference. + +Signature: + +```typescript +onCloudParams?: ModelParams; +``` + +## HybridParams.onDeviceParams + +Optional. Specifies advanced params for on-device inference. + +Signature: + +```typescript +onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; +``` diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index fca51b42f4f..7ba01010598 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -19,7 +19,7 @@ The Vertex AI in Firebase Web SDK. | function(app, ...) | | [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance for the given app. | | function(vertexAI, ...) | -| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3037c9) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | +| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_8dbc150) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | | [getImagenModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getimagenmodel_812c375) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | ## Classes @@ -55,6 +55,7 @@ The Vertex AI in Firebase Web SDK. | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | | [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | | [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | +| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or on-cloud. | | [Modality](./vertexai.md#modality) | Content part modality. | | [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. | @@ -91,6 +92,7 @@ The Vertex AI in Firebase Web SDK. | [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. | | [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | | | [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. | +| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Configures on-device and on-cloud inference. | | [ImagenGCSImage](./vertexai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.This feature is not available yet. | | [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. | | [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | (Public Preview) The response from a request to generate images with Imagen. | @@ -99,10 +101,10 @@ The Vertex AI in Firebase Web SDK. | [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | | [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | -| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). | +| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150). | | [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. | | [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | -| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). | +| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150). | | [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | @@ -160,14 +162,14 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions ## function(vertexAI, ...) -### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_e3037c9} +### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_8dbc150} Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. Signature: ```typescript -export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel; ``` #### Parameters @@ -175,7 +177,7 @@ export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: Mode | Parameter | Type | Description | | --- | --- | --- | | vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | | -| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | +| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) \| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | Returns: @@ -489,6 +491,24 @@ export declare enum ImagenSafetyFilterLevel | BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | | BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | +## InferenceMode + +Determines whether inference happens on-device or on-cloud. + +Signature: + +```typescript +export declare enum InferenceMode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ONLY\_ON\_CLOUD | "ONLY_ON_CLOUD" | Exclusively uses the on-cloud model. | +| ONLY\_ON\_DEVICE | "ONLY_ON_DEVICE" | Exclusively uses the on-device model. Throws if one is not available. | +| PREFER\_ON\_DEVICE | "PREFER_ON_DEVICE" | Uses the on-device model if available, or falls back to the on-cloud model. | + ## Modality Content part modality. diff --git a/docs-devsite/vertexai.modelparams.md b/docs-devsite/vertexai.modelparams.md index 590bc14e435..fe7b7d37c30 100644 --- a/docs-devsite/vertexai.modelparams.md +++ b/docs-devsite/vertexai.modelparams.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # ModelParams interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150). Signature: diff --git a/docs-devsite/vertexai.requestoptions.md b/docs-devsite/vertexai.requestoptions.md index 6d074775520..9e174c12a32 100644 --- a/docs-devsite/vertexai.requestoptions.md +++ b/docs-devsite/vertexai.requestoptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # RequestOptions interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_8dbc150). Signature: From ae1c25455f9fa6216e2aafe3e206f95a895c9f15 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Thu, 27 Mar 2025 16:41:07 -0700 Subject: [PATCH 10/16] Use in-cloud phrasing --- packages/vertexai/src/api.test.ts | 4 ++-- packages/vertexai/src/api.ts | 10 +++++----- packages/vertexai/src/types/enums.ts | 8 ++++---- packages/vertexai/src/types/requests.ts | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index bf97facb198..030fb086d95 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -108,8 +108,8 @@ describe('Top level API', () => { }); it('getGenerativeModel with HybridParams sets the model', () => { const genModel = getGenerativeModel(fakeVertexAI, { - mode: InferenceMode.ONLY_ON_CLOUD, - onCloudParams: { model: 'my-model' } + mode: InferenceMode.ONLY_IN_CLOUD, + inCloudParams: { model: 'my-model' } }); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 60bf9fcb006..f09b50ea53b 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -76,22 +76,22 @@ export function getGenerativeModel( ): GenerativeModel { // Uses the existence of HybridParams.mode to clarify the type of the modelParams input. const hybridParams = modelParams as HybridParams; - let onCloudParams: ModelParams; + let inCloudParams: ModelParams; if (hybridParams.mode) { - onCloudParams = hybridParams.onCloudParams || { + inCloudParams = hybridParams.inCloudParams || { model: 'gemini-2.0-flash-lite' }; } else { - onCloudParams = modelParams as ModelParams; + inCloudParams = modelParams as ModelParams; } - if (!onCloudParams.model) { + if (!inCloudParams.model) { throw new VertexAIError( VertexAIErrorCode.NO_MODEL, `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })` ); } - return new GenerativeModel(vertexAI, onCloudParams, requestOptions); + return new GenerativeModel(vertexAI, inCloudParams, requestOptions); } /** diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index 0955aebc9cf..953078033b3 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -242,12 +242,12 @@ export enum Modality { } /** - * Determines whether inference happens on-device or on-cloud. + * Determines whether inference happens on-device or in-cloud. * @public */ export enum InferenceMode { /** - * Uses the on-device model if available, or falls back to the on-cloud model. + * Uses the on-device model if available, or falls back to the in-cloud model. */ PREFER_ON_DEVICE = 'PREFER_ON_DEVICE', @@ -257,7 +257,7 @@ export enum InferenceMode { ONLY_ON_DEVICE = 'ONLY_ON_DEVICE', /** - * Exclusively uses the on-cloud model. + * Exclusively uses the in-cloud model. */ - ONLY_ON_CLOUD = 'ONLY_ON_CLOUD' + ONLY_IN_CLOUD = 'ONLY_IN_CLOUD' } diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 283b79af66c..e6f852e1e3f 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -216,12 +216,12 @@ export interface FunctionCallingConfig { } /** - * Configures on-device and on-cloud inference. + * Configures on-device and in-cloud inference. * @public */ export interface HybridParams { /** - * Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. + * Optional. Specifies on-device or in-cloud inference. Defaults to prefer on-device. */ mode?: InferenceMode; /** @@ -229,7 +229,7 @@ export interface HybridParams { */ onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; /** - * Optional. Specifies advanced params for on-cloud inference. + * Optional. Specifies advanced params for in-cloud inference. */ - onCloudParams?: ModelParams; + inCloudParams?: ModelParams; } From 559bd138c6f701b988ba24abb0d07ed9bda8c205 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Fri, 28 Mar 2025 16:41:54 -0700 Subject: [PATCH 11/16] Parameterize default in-cloud model name --- common/api-review/vertexai.api.md | 7 ++++--- packages/vertexai/src/api.test.ts | 10 +++++++++- packages/vertexai/src/api.ts | 2 +- packages/vertexai/src/models/generative-model.ts | 4 ++++ packages/vertexai/src/types/enums.ts | 1 - packages/vertexai/src/types/requests.ts | 7 +++---- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 0af6e07f19e..d452077f313 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -326,6 +326,7 @@ export interface GenerativeContentBlob { export class GenerativeModel extends VertexAIModel { constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions); countTokens(request: CountTokensRequest | string | Array): Promise; + static DEFAULT_HYBRID_IN_CLOUD_MODEL: string; generateContent(request: GenerateContentRequest | string | Array): Promise; generateContentStream(request: GenerateContentRequest | string | Array): Promise; // (undocumented) @@ -418,8 +419,8 @@ export enum HarmSeverity { // @public export interface HybridParams { - mode?: InferenceMode; - onCloudParams?: ModelParams; + inCloudParams?: ModelParams; + mode: InferenceMode; onDeviceParams?: AILanguageModelCreateOptionsWithSystemPrompt; } @@ -509,7 +510,7 @@ export interface ImagenSafetySettings { // @public export enum InferenceMode { - ONLY_ON_CLOUD = "ONLY_ON_CLOUD", + ONLY_IN_CLOUD = "ONLY_IN_CLOUD", ONLY_ON_DEVICE = "ONLY_ON_DEVICE", PREFER_ON_DEVICE = "PREFER_ON_DEVICE" } diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 030fb086d95..aeb090e24c5 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -106,7 +106,15 @@ describe('Top level API', () => { expect(genModel).to.be.an.instanceOf(GenerativeModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); - it('getGenerativeModel with HybridParams sets the model', () => { + it('getGenerativeModel with HybridParams sets a default model', () => { + const genModel = getGenerativeModel(fakeVertexAI, { + mode: InferenceMode.ONLY_ON_DEVICE + }); + expect(genModel.model).to.equal( + `publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}` + ); + }); + it('getGenerativeModel with HybridParams honors a model override', () => { const genModel = getGenerativeModel(fakeVertexAI, { mode: InferenceMode.ONLY_IN_CLOUD, inCloudParams: { model: 'my-model' } diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index f09b50ea53b..64bf4231edb 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -79,7 +79,7 @@ export function getGenerativeModel( let inCloudParams: ModelParams; if (hybridParams.mode) { inCloudParams = hybridParams.inCloudParams || { - model: 'gemini-2.0-flash-lite' + model: GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL }; } else { inCloudParams = modelParams as ModelParams; diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index b4cf464f025..76e76bfb8d2 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -49,6 +49,10 @@ import { VertexAIModel } from './vertexai-model'; * @public */ export class GenerativeModel extends VertexAIModel { + /** + * Defines the name of the default in-cloud model to use for hybrid inference. + */ + static DEFAULT_HYBRID_IN_CLOUD_MODEL = 'gemini-2.0-flash-lite'; generationConfig: GenerationConfig; safetySettings: SafetySetting[]; requestOptions?: RequestOptions; diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index 953078033b3..57629e5c9f5 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -243,7 +243,6 @@ export enum Modality { /** * Determines whether inference happens on-device or in-cloud. - * @public */ export enum InferenceMode { /** diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index e6f852e1e3f..baaf289031a 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -216,14 +216,13 @@ export interface FunctionCallingConfig { } /** - * Configures on-device and in-cloud inference. - * @public + * Toggles hybrid inference. */ export interface HybridParams { /** - * Optional. Specifies on-device or in-cloud inference. Defaults to prefer on-device. + * Specifies on-device or in-cloud inference. Defaults to prefer on-device. */ - mode?: InferenceMode; + mode: InferenceMode; /** * Optional. Specifies advanced params for on-device inference. */ From 814a1dc9559dda0593a93e7351d6b070d52dab1b Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Tue, 1 Apr 2025 17:44:30 -0700 Subject: [PATCH 12/16] Use type for inference mode and update docs --- common/api-review/vertexai.api.md | 6 +---- docs-devsite/vertexai.generativemodel.md | 11 ++++++++ docs-devsite/vertexai.hybridparams.md | 18 ++++++------- docs-devsite/vertexai.md | 32 +++++++++--------------- packages/vertexai/src/api.test.ts | 5 ++-- packages/vertexai/src/types/enums.ts | 20 --------------- packages/vertexai/src/types/requests.ts | 10 ++++++-- 7 files changed, 43 insertions(+), 59 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index d452077f313..ef7d0b4f300 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -509,11 +509,7 @@ export interface ImagenSafetySettings { } // @public -export enum InferenceMode { - ONLY_IN_CLOUD = "ONLY_IN_CLOUD", - ONLY_ON_DEVICE = "ONLY_ON_DEVICE", - PREFER_ON_DEVICE = "PREFER_ON_DEVICE" -} +export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud'; // @public export interface InlineDataPart { diff --git a/docs-devsite/vertexai.generativemodel.md b/docs-devsite/vertexai.generativemodel.md index b734e241e78..762e52254e6 100644 --- a/docs-devsite/vertexai.generativemodel.md +++ b/docs-devsite/vertexai.generativemodel.md @@ -29,6 +29,7 @@ export declare class GenerativeModel extends VertexAIModel | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL](./vertexai.generativemodel.md#generativemodeldefault_hybrid_in_cloud_model) | static | string | Defines the name of the default in-cloud model to use for hybrid inference. | | [generationConfig](./vertexai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | | | [requestOptions](./vertexai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | | [safetySettings](./vertexai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface)\[\] | | @@ -63,6 +64,16 @@ constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: Reque | modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | +## GenerativeModel.DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL + +Defines the name of the default in-cloud model to use for hybrid inference. + +Signature: + +```typescript +static DEFAULT_HYBRID_IN_CLOUD_MODEL: string; +``` + ## GenerativeModel.generationConfig Signature: diff --git a/docs-devsite/vertexai.hybridparams.md b/docs-devsite/vertexai.hybridparams.md index 9f340babccf..912f5e43c36 100644 --- a/docs-devsite/vertexai.hybridparams.md +++ b/docs-devsite/vertexai.hybridparams.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # HybridParams interface -Configures on-device and on-cloud inference. +Toggles hybrid inference. Signature: @@ -22,28 +22,28 @@ export interface HybridParams | Property | Type | Description | | --- | --- | --- | -| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. | -| [onCloudParams](./vertexai.hybridparams.md#hybridparamsoncloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for on-cloud inference. | +| [inCloudParams](./vertexai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. | +| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. | | [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | AILanguageModelCreateOptionsWithSystemPrompt | Optional. Specifies advanced params for on-device inference. | -## HybridParams.mode +## HybridParams.inCloudParams -Optional. Specifies on-device or on-cloud inference. Defaults to prefer on-device. +Optional. Specifies advanced params for in-cloud inference. Signature: ```typescript -mode?: InferenceMode; +inCloudParams?: ModelParams; ``` -## HybridParams.onCloudParams +## HybridParams.mode -Optional. Specifies advanced params for on-cloud inference. +Specifies on-device or in-cloud inference. Defaults to prefer on-device. Signature: ```typescript -onCloudParams?: ModelParams; +mode: InferenceMode; ``` ## HybridParams.onDeviceParams diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index 7ba01010598..efe0e196a6e 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -55,7 +55,6 @@ The Vertex AI in Firebase Web SDK. | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | | [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | | [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | -| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or on-cloud. | | [Modality](./vertexai.md#modality) | Content part modality. | | [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. | @@ -92,7 +91,7 @@ The Vertex AI in Firebase Web SDK. | [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. | | [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | | | [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. | -| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Configures on-device and on-cloud inference. | +| [HybridParams](./vertexai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. | | [ImagenGCSImage](./vertexai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.This feature is not available yet. | | [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. | | [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | (Public Preview) The response from a request to generate images with Imagen. | @@ -132,6 +131,7 @@ The Vertex AI in Firebase Web SDK. | Type Alias | Description | | --- | --- | +| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. | | [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | | [Role](./vertexai.md#role) | Role is the producer of the content. | | [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | @@ -225,6 +225,16 @@ Possible roles. POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] ``` +## InferenceMode + +Determines whether inference happens on-device or in-cloud. + +Signature: + +```typescript +export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud'; +``` + ## Part Content part - includes text, image/video, or function call/response part types. @@ -491,24 +501,6 @@ export declare enum ImagenSafetyFilterLevel | BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | | BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | -## InferenceMode - -Determines whether inference happens on-device or on-cloud. - -Signature: - -```typescript -export declare enum InferenceMode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ONLY\_ON\_CLOUD | "ONLY_ON_CLOUD" | Exclusively uses the on-cloud model. | -| ONLY\_ON\_DEVICE | "ONLY_ON_DEVICE" | Exclusively uses the on-device model. Throws if one is not available. | -| PREFER\_ON\_DEVICE | "PREFER_ON_DEVICE" | Uses the on-device model if available, or falls back to the on-cloud model. | - ## Modality Content part modality. diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index aeb090e24c5..0f25384071a 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -16,7 +16,6 @@ */ import { ImagenModelParams, - InferenceMode, ModelParams, VertexAIErrorCode } from './types'; @@ -108,7 +107,7 @@ describe('Top level API', () => { }); it('getGenerativeModel with HybridParams sets a default model', () => { const genModel = getGenerativeModel(fakeVertexAI, { - mode: InferenceMode.ONLY_ON_DEVICE + mode: 'only_on_device' }); expect(genModel.model).to.equal( `publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}` @@ -116,7 +115,7 @@ describe('Top level API', () => { }); it('getGenerativeModel with HybridParams honors a model override', () => { const genModel = getGenerativeModel(fakeVertexAI, { - mode: InferenceMode.ONLY_IN_CLOUD, + mode: 'only_in_cloud', inCloudParams: { model: 'my-model' } }); expect(genModel.model).to.equal('publishers/google/models/my-model'); diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index 57629e5c9f5..a9481d40f5f 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -240,23 +240,3 @@ export enum Modality { */ DOCUMENT = 'DOCUMENT' } - -/** - * Determines whether inference happens on-device or in-cloud. - */ -export enum InferenceMode { - /** - * Uses the on-device model if available, or falls back to the in-cloud model. - */ - PREFER_ON_DEVICE = 'PREFER_ON_DEVICE', - - /** - * Exclusively uses the on-device model. Throws if one is not available. - */ - ONLY_ON_DEVICE = 'ONLY_ON_DEVICE', - - /** - * Exclusively uses the in-cloud model. - */ - ONLY_IN_CLOUD = 'ONLY_IN_CLOUD' -} diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index baaf289031a..df2bd2573c1 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -21,8 +21,7 @@ import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, - HarmCategory, - InferenceMode + HarmCategory } from './enums'; import { ObjectSchemaInterface, SchemaRequest } from './schema'; @@ -232,3 +231,10 @@ export interface HybridParams { */ inCloudParams?: ModelParams; } +/** + * Determines whether inference happens on-device or in-cloud. + */ +export type InferenceMode = + | 'prefer_on_device' + | 'only_on_device' + | 'only_in_cloud'; From 78fed95fa59cfbf08875266566a9a53925c7dc10 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Thu, 3 Apr 2025 13:58:15 -0700 Subject: [PATCH 13/16] Run yarn format --- packages/vertexai/src/api.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 0f25384071a..2852e9c3f1f 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -14,11 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - ImagenModelParams, - ModelParams, - VertexAIErrorCode -} from './types'; +import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types'; import { VertexAIError } from './errors'; import { ImagenModel, getGenerativeModel, getImagenModel } from './api'; import { expect } from 'chai'; From 8302584b847e8c8e97d2f0a7dfdfb90a7f6c4710 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 14 Apr 2025 16:07:16 -0700 Subject: [PATCH 14/16] rebased and updated deps --- package.json | 21 ++++--- packages/vertexai/package.json | 5 +- scripts/release/utils/workspace.ts | 6 +- yarn.lock | 92 +++++++++++++++++++++++++++--- 4 files changed, 103 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index bff8b2c715e..91a1c9316de 100644 --- a/package.json +++ b/package.json @@ -56,11 +56,16 @@ "type": "git", "url": "git+https://github.com/firebase/firebase-js-sdk.git" }, - "workspaces": [ - "packages/*", - "integration/*", - "repo-scripts/*" - ], + "workspaces": { + "packages": [ + "packages/*", + "integration/*", + "repo-scripts/*" + ], + "nohoist": [ + "**/vertexai/@types/dom-chromium-ai" + ] + }, "devDependencies": { "@babel/core": "7.26.8", "@babel/plugin-transform-modules-commonjs": "7.26.3", @@ -80,7 +85,7 @@ "@types/long": "4.0.2", "@types/mocha": "9.1.1", "@types/mz": "2.7.8", - "@types/node": "18.19.75", + "@types/node": "18.19.83", "@types/request": "2.48.12", "@types/sinon": "9.0.11", "@types/sinon-chai": "3.2.12", @@ -139,7 +144,7 @@ "nyc": "15.1.0", "ora": "5.4.1", "patch-package": "7.0.2", - "playwright": "1.50.1", + "playwright": "1.51.1", "postinstall-postinstall": "2.1.0", "prettier": "2.8.8", "protractor": "5.4.2", @@ -158,7 +163,7 @@ "typedoc": "0.16.11", "typescript": "5.5.4", "watch": "1.0.2", - "webpack": "5.97.1", + "webpack": "5.98.0", "yargs": "17.7.2" } } diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index 20c21a2bfea..cb7989eaf12 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -1,6 +1,6 @@ { "name": "@firebase/vertexai", - "version": "1.2.0", + "version": "1.2.1", "description": "A Firebase SDK for VertexAI", "author": "Firebase (https://firebase.google.com/)", "engines": { @@ -52,11 +52,12 @@ "@firebase/component": "0.6.13", "@firebase/logger": "0.4.4", "@firebase/util": "1.11.0", + "@types/dom-chromium-ai": "0.0.6", "tslib": "^2.1.0" }, "license": "Apache-2.0", "devDependencies": { - "@firebase/app": "0.11.3", + "@firebase/app": "0.11.4", "@rollup/plugin-json": "6.1.0", "rollup": "2.79.2", "rollup-plugin-replace": "2.2.0", diff --git a/scripts/release/utils/workspace.ts b/scripts/release/utils/workspace.ts index 077e3124b2a..3dba8651675 100644 --- a/scripts/release/utils/workspace.ts +++ b/scripts/release/utils/workspace.ts @@ -27,8 +27,10 @@ const writeFile = promisify(_writeFile); const { workspaces: rawWorkspaces -}: { workspaces: string[] } = require(`${root}/package.json`); -const workspaces = rawWorkspaces.map(workspace => `${root}/${workspace}`); +}: { workspaces: { packages: string[] } } = require(`${root}/package.json`); +const workspaces = rawWorkspaces.packages.map( + workspace => `${root}/${workspace}` +); export function mapWorkspaceToPackages( workspaces: string[] diff --git a/yarn.lock b/yarn.lock index 5e5947884f9..f6d95117044 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1299,6 +1299,28 @@ resolved "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2" integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q== +"@firebase/app@0.11.4": + version "0.11.4" + resolved "https://registry.npmjs.org/@firebase/app/-/app-0.11.4.tgz#93f2637ed5b8dbc1ddf879c727d66a00c656c959" + integrity sha512-GPREsZjfSaHzwyC6cI/Cqvzf6zxqMzya+25tSpUstdqC2w0IdfxEfOMjfdW7bDfVEf4Rb4Nb6gfoOAgVSp4c4g== + dependencies: + "@firebase/component" "0.6.13" + "@firebase/logger" "0.4.4" + "@firebase/util" "1.11.0" + idb "7.1.1" + tslib "^2.1.0" + +"@firebase/vertexai@1.2.0": + version "1.2.0" + resolved "https://registry.npmjs.org/@firebase/vertexai/-/vertexai-1.2.0.tgz#8f8a4ae75284c3067c0a06c7d0bef922571e6dd7" + integrity sha512-WUYIzFpOipjFXT2i0hT26wivJoIximizQptVs3KAxFAqbVlO8sjKPsMkgz0bh+tdKlqP4SUDda71fMUZXUKHgA== + dependencies: + "@firebase/app-check-interop-types" "0.3.3" + "@firebase/component" "0.6.13" + "@firebase/logger" "0.4.4" + "@firebase/util" "1.11.0" + tslib "^2.1.0" + "@gar/promisify@^1.0.1": version "1.1.3" resolved "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6" @@ -2949,6 +2971,11 @@ resolved "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz#334311971d3a07121e7eb91b684a605e7eea9cbd" integrity sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw== +"@types/dom-chromium-ai@0.0.6": + version "0.0.6" + resolved "https://registry.npmjs.org/@types/dom-chromium-ai/-/dom-chromium-ai-0.0.6.tgz#0c9e5712d8db3d26586cd9f175001b509cd2e514" + integrity sha512-/jUGe9a3BLzsjjg18Olk/Ul64PZ0P4aw8uNxrXeXVTni5PSxyCfyhHb4UohsXNVByOnwYGzlqUcb3vYKVsG4mg== + "@types/eslint-scope@^3.7.7": version "3.7.7" resolved "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5" @@ -3168,6 +3195,13 @@ dependencies: undici-types "~5.26.4" +"@types/node@18.19.83": + version "18.19.83" + resolved "https://registry.npmjs.org/@types/node/-/node-18.19.83.tgz#44d302cd09364640bdd45d001bc75e596f7da920" + integrity sha512-D69JeR5SfFS5H6FLbUaS0vE4r1dGhmMBbG4Ed6BNS4wkDK8GZjsdCShT5LCN59vOHEUHnFCY9J4aclXlIphMkA== + dependencies: + undici-types "~5.26.4" + "@types/node@^12.7.1": version "12.20.55" resolved "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" @@ -13285,17 +13319,17 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -playwright-core@1.50.1: - version "1.50.1" - resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.50.1.tgz#6a0484f1f1c939168f40f0ab3828c4a1592c4504" - integrity sha512-ra9fsNWayuYumt+NiM069M6OkcRb1FZSK8bgi66AtpFoWkg2+y0bJSNmkFrWhMbEBbVKC/EruAHH3g0zmtwGmQ== +playwright-core@1.51.1: + version "1.51.1" + resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.51.1.tgz#d57f0393e02416f32a47cf82b27533656a8acce1" + integrity sha512-/crRMj8+j/Nq5s8QcvegseuyeZPxpQCZb6HNk3Sos3BlZyAknRjoyJPFWkpNn8v0+P3WiwqFF8P+zQo4eqiNuw== -playwright@1.50.1: - version "1.50.1" - resolved "https://registry.npmjs.org/playwright/-/playwright-1.50.1.tgz#2f93216511d65404f676395bfb97b41aa052b180" - integrity sha512-G8rwsOQJ63XG6BbKj2w5rHeavFjy5zynBA9zsJMMtBoe/Uf757oG12NXz6e6OirF7RCrTVAKFXbLmn1RbL7Qaw== +playwright@1.51.1: + version "1.51.1" + resolved "https://registry.npmjs.org/playwright/-/playwright-1.51.1.tgz#ae1467ee318083968ad28d6990db59f47a55390f" + integrity sha512-kkx+MB2KQRkyxjYPc3a0wLZZoDczmppyGJIvQ43l+aZihkaVvmu/21kiyaHeHjiFxjxNNFnUncKmcGIyOojsaw== dependencies: - playwright-core "1.50.1" + playwright-core "1.51.1" optionalDependencies: fsevents "2.3.2" @@ -15839,6 +15873,17 @@ terser-webpack-plugin@^5.3.10: serialize-javascript "^6.0.2" terser "^5.31.1" +terser-webpack-plugin@^5.3.11: + version "5.3.14" + resolved "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.14.tgz#9031d48e57ab27567f02ace85c7d690db66c3e06" + integrity sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw== + dependencies: + "@jridgewell/trace-mapping" "^0.3.25" + jest-worker "^27.4.5" + schema-utils "^4.3.0" + serialize-javascript "^6.0.2" + terser "^5.31.1" + terser@5.37.0, terser@^5.17.4, terser@^5.31.1: version "5.37.0" resolved "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz#38aa66d1cfc43d0638fab54e43ff8a4f72a21ba3" @@ -16987,6 +17032,35 @@ webpack@5.97.1, webpack@^5: watchpack "^2.4.1" webpack-sources "^3.2.3" +webpack@5.98.0: + version "5.98.0" + resolved "https://registry.npmjs.org/webpack/-/webpack-5.98.0.tgz#44ae19a8f2ba97537978246072fb89d10d1fbd17" + integrity sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA== + dependencies: + "@types/eslint-scope" "^3.7.7" + "@types/estree" "^1.0.6" + "@webassemblyjs/ast" "^1.14.1" + "@webassemblyjs/wasm-edit" "^1.14.1" + "@webassemblyjs/wasm-parser" "^1.14.1" + acorn "^8.14.0" + browserslist "^4.24.0" + chrome-trace-event "^1.0.2" + enhanced-resolve "^5.17.1" + es-module-lexer "^1.2.1" + eslint-scope "5.1.1" + events "^3.2.0" + glob-to-regexp "^0.4.1" + graceful-fs "^4.2.11" + json-parse-even-better-errors "^2.3.1" + loader-runner "^4.2.0" + mime-types "^2.1.27" + neo-async "^2.6.2" + schema-utils "^4.3.0" + tapable "^2.1.1" + terser-webpack-plugin "^5.3.11" + watchpack "^2.4.1" + webpack-sources "^3.2.3" + websocket-driver@>=0.5.1: version "0.7.4" resolved "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz#89ad5295bbf64b480abcba31e4953aca706f5760" From d8f8fb379555222da9863af61cf4df2746a1309d Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 14 Apr 2025 16:11:47 -0700 Subject: [PATCH 15/16] revert deps --- package.json | 6 +-- packages/vertexai/package.json | 6 +-- yarn.lock | 87 ++++------------------------------ 3 files changed, 15 insertions(+), 84 deletions(-) diff --git a/package.json b/package.json index 91a1c9316de..43589733b54 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "@types/long": "4.0.2", "@types/mocha": "9.1.1", "@types/mz": "2.7.8", - "@types/node": "18.19.83", + "@types/node": "18.19.75", "@types/request": "2.48.12", "@types/sinon": "9.0.11", "@types/sinon-chai": "3.2.12", @@ -144,7 +144,7 @@ "nyc": "15.1.0", "ora": "5.4.1", "patch-package": "7.0.2", - "playwright": "1.51.1", + "playwright": "1.50.1", "postinstall-postinstall": "2.1.0", "prettier": "2.8.8", "protractor": "5.4.2", @@ -163,7 +163,7 @@ "typedoc": "0.16.11", "typescript": "5.5.4", "watch": "1.0.2", - "webpack": "5.98.0", + "webpack": "5.97.1", "yargs": "17.7.2" } } diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index cb7989eaf12..d0029856c6e 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -1,6 +1,6 @@ { "name": "@firebase/vertexai", - "version": "1.2.1", + "version": "1.2.0", "description": "A Firebase SDK for VertexAI", "author": "Firebase (https://firebase.google.com/)", "engines": { @@ -57,7 +57,7 @@ }, "license": "Apache-2.0", "devDependencies": { - "@firebase/app": "0.11.4", + "@firebase/app": "0.11.3", "@rollup/plugin-json": "6.1.0", "rollup": "2.79.2", "rollup-plugin-replace": "2.2.0", @@ -79,4 +79,4 @@ ], "reportDir": "./coverage/node" } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f6d95117044..920547a19f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1299,28 +1299,6 @@ resolved "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2" integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q== -"@firebase/app@0.11.4": - version "0.11.4" - resolved "https://registry.npmjs.org/@firebase/app/-/app-0.11.4.tgz#93f2637ed5b8dbc1ddf879c727d66a00c656c959" - integrity sha512-GPREsZjfSaHzwyC6cI/Cqvzf6zxqMzya+25tSpUstdqC2w0IdfxEfOMjfdW7bDfVEf4Rb4Nb6gfoOAgVSp4c4g== - dependencies: - "@firebase/component" "0.6.13" - "@firebase/logger" "0.4.4" - "@firebase/util" "1.11.0" - idb "7.1.1" - tslib "^2.1.0" - -"@firebase/vertexai@1.2.0": - version "1.2.0" - resolved "https://registry.npmjs.org/@firebase/vertexai/-/vertexai-1.2.0.tgz#8f8a4ae75284c3067c0a06c7d0bef922571e6dd7" - integrity sha512-WUYIzFpOipjFXT2i0hT26wivJoIximizQptVs3KAxFAqbVlO8sjKPsMkgz0bh+tdKlqP4SUDda71fMUZXUKHgA== - dependencies: - "@firebase/app-check-interop-types" "0.3.3" - "@firebase/component" "0.6.13" - "@firebase/logger" "0.4.4" - "@firebase/util" "1.11.0" - tslib "^2.1.0" - "@gar/promisify@^1.0.1": version "1.1.3" resolved "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6" @@ -3195,13 +3173,6 @@ dependencies: undici-types "~5.26.4" -"@types/node@18.19.83": - version "18.19.83" - resolved "https://registry.npmjs.org/@types/node/-/node-18.19.83.tgz#44d302cd09364640bdd45d001bc75e596f7da920" - integrity sha512-D69JeR5SfFS5H6FLbUaS0vE4r1dGhmMBbG4Ed6BNS4wkDK8GZjsdCShT5LCN59vOHEUHnFCY9J4aclXlIphMkA== - dependencies: - undici-types "~5.26.4" - "@types/node@^12.7.1": version "12.20.55" resolved "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" @@ -13319,17 +13290,17 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -playwright-core@1.51.1: - version "1.51.1" - resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.51.1.tgz#d57f0393e02416f32a47cf82b27533656a8acce1" - integrity sha512-/crRMj8+j/Nq5s8QcvegseuyeZPxpQCZb6HNk3Sos3BlZyAknRjoyJPFWkpNn8v0+P3WiwqFF8P+zQo4eqiNuw== +playwright-core@1.50.1: + version "1.50.1" + resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.50.1.tgz#6a0484f1f1c939168f40f0ab3828c4a1592c4504" + integrity sha512-ra9fsNWayuYumt+NiM069M6OkcRb1FZSK8bgi66AtpFoWkg2+y0bJSNmkFrWhMbEBbVKC/EruAHH3g0zmtwGmQ== -playwright@1.51.1: - version "1.51.1" - resolved "https://registry.npmjs.org/playwright/-/playwright-1.51.1.tgz#ae1467ee318083968ad28d6990db59f47a55390f" - integrity sha512-kkx+MB2KQRkyxjYPc3a0wLZZoDczmppyGJIvQ43l+aZihkaVvmu/21kiyaHeHjiFxjxNNFnUncKmcGIyOojsaw== +playwright@1.50.1: + version "1.50.1" + resolved "https://registry.npmjs.org/playwright/-/playwright-1.50.1.tgz#2f93216511d65404f676395bfb97b41aa052b180" + integrity sha512-G8rwsOQJ63XG6BbKj2w5rHeavFjy5zynBA9zsJMMtBoe/Uf757oG12NXz6e6OirF7RCrTVAKFXbLmn1RbL7Qaw== dependencies: - playwright-core "1.51.1" + playwright-core "1.50.1" optionalDependencies: fsevents "2.3.2" @@ -15873,17 +15844,6 @@ terser-webpack-plugin@^5.3.10: serialize-javascript "^6.0.2" terser "^5.31.1" -terser-webpack-plugin@^5.3.11: - version "5.3.14" - resolved "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.14.tgz#9031d48e57ab27567f02ace85c7d690db66c3e06" - integrity sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw== - dependencies: - "@jridgewell/trace-mapping" "^0.3.25" - jest-worker "^27.4.5" - schema-utils "^4.3.0" - serialize-javascript "^6.0.2" - terser "^5.31.1" - terser@5.37.0, terser@^5.17.4, terser@^5.31.1: version "5.37.0" resolved "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz#38aa66d1cfc43d0638fab54e43ff8a4f72a21ba3" @@ -17032,35 +16992,6 @@ webpack@5.97.1, webpack@^5: watchpack "^2.4.1" webpack-sources "^3.2.3" -webpack@5.98.0: - version "5.98.0" - resolved "https://registry.npmjs.org/webpack/-/webpack-5.98.0.tgz#44ae19a8f2ba97537978246072fb89d10d1fbd17" - integrity sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA== - dependencies: - "@types/eslint-scope" "^3.7.7" - "@types/estree" "^1.0.6" - "@webassemblyjs/ast" "^1.14.1" - "@webassemblyjs/wasm-edit" "^1.14.1" - "@webassemblyjs/wasm-parser" "^1.14.1" - acorn "^8.14.0" - browserslist "^4.24.0" - chrome-trace-event "^1.0.2" - enhanced-resolve "^5.17.1" - es-module-lexer "^1.2.1" - eslint-scope "5.1.1" - events "^3.2.0" - glob-to-regexp "^0.4.1" - graceful-fs "^4.2.11" - json-parse-even-better-errors "^2.3.1" - loader-runner "^4.2.0" - mime-types "^2.1.27" - neo-async "^2.6.2" - schema-utils "^4.3.0" - tapable "^2.1.1" - terser-webpack-plugin "^5.3.11" - watchpack "^2.4.1" - webpack-sources "^3.2.3" - websocket-driver@>=0.5.1: version "0.7.4" resolved "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz#89ad5295bbf64b480abcba31e4953aca706f5760" From 3ec2857853dbf73e3112ebf8162658d0e32b9878 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Tue, 15 Apr 2025 10:45:48 -0700 Subject: [PATCH 16/16] Remove erroneous type dep --- packages/vertexai/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index c53cb5d3f48..09f4d80b4d5 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -52,7 +52,6 @@ "@firebase/component": "0.6.13", "@firebase/logger": "0.4.4", "@firebase/util": "1.11.0", - "@types/dom-chromium-ai": "0.0.6", "tslib": "^2.1.0" }, "license": "Apache-2.0",