diff --git a/js/plugins/googleai/src/embedder.ts b/js/plugins/googleai/src/embedder.ts index 531ac8a0e5..0bb36b9455 100644 --- a/js/plugins/googleai/src/embedder.ts +++ b/js/plugins/googleai/src/embedder.ts @@ -23,9 +23,9 @@ import { z, type EmbedderAction, type EmbedderReference, - type Genkit, } from 'genkit'; -import { embedderRef } from 'genkit/embedder'; +import { embedderRef as createEmbedderRef } from 'genkit/embedder'; +import { embedder } from 'genkit/plugin'; import { getApiKeyFromEnvVar } from './common.js'; import type { PluginOptions } from './index.js'; @@ -60,7 +60,7 @@ export const GeminiEmbeddingConfigSchema = z.object({ export type GeminiEmbeddingConfig = z.infer; -export const textEmbeddingGecko001 = embedderRef({ +export const textEmbeddingGecko001 = createEmbedderRef({ name: 'googleai/embedding-001', configSchema: GeminiEmbeddingConfigSchema, info: { @@ -72,7 +72,7 @@ export const textEmbeddingGecko001 = embedderRef({ }, }); -export const textEmbedding004 = embedderRef({ +export const textEmbedding004 = createEmbedderRef({ name: 'googleai/text-embedding-004', configSchema: GeminiEmbeddingConfigSchema, info: { @@ -84,7 +84,7 @@ export const textEmbedding004 = embedderRef({ }, }); -export const geminiEmbedding001 = embedderRef({ +export const geminiEmbedding001 = createEmbedderRef({ name: 'googleai/gemini-embedding-001', configSchema: GeminiEmbeddingConfigSchema, info: { @@ -103,7 +103,6 @@ export const SUPPORTED_MODELS = { }; export function defineGoogleAIEmbedder( - ai: Genkit, name: string, pluginOptions: PluginOptions ): EmbedderAction { @@ -117,9 +116,9 @@ export function defineGoogleAIEmbedder( 'For more details see https://genkit.dev/docs/plugins/google-genai' ); } - const embedder: EmbedderReference = + const embedderRef: EmbedderReference = SUPPORTED_MODELS[name] ?? - embedderRef({ + createEmbedderRef({ name: name, configSchema: GeminiEmbeddingConfigSchema, info: { @@ -130,16 +129,16 @@ export function defineGoogleAIEmbedder( }, }, }); - const apiModelName = embedder.name.startsWith('googleai/') - ? embedder.name.substring('googleai/'.length) - : embedder.name; - return ai.defineEmbedder( + const apiModelName = embedderRef.name.startsWith('googleai/') + ? embedderRef.name.substring('googleai/'.length) + : embedderRef.name; + return embedder( { - name: embedder.name, + name: embedderRef.name, configSchema: GeminiEmbeddingConfigSchema, - info: embedder.info!, + info: embedderRef.info!, }, - async (input, options) => { + async ({ input, options }) => { if (pluginOptions.apiKey === false && !options?.apiKey) { throw new GenkitError({ status: 'INVALID_ARGUMENT', @@ -152,8 +151,8 @@ export function defineGoogleAIEmbedder( ).getGenerativeModel({ model: options?.version || - embedder.config?.version || - embedder.version || + embedderRef.config?.version || + embedderRef.version || apiModelName, }); const embeddings = await Promise.all( diff --git a/js/plugins/googleai/src/gemini.ts b/js/plugins/googleai/src/gemini.ts index 38d8285856..487de8bafb 100644 --- a/js/plugins/googleai/src/gemini.ts +++ b/js/plugins/googleai/src/gemini.ts @@ -38,12 +38,12 @@ import { type ToolConfig, type UsageMetadata, } from '@google/generative-ai'; -import { GenkitError, z, type Genkit, type JSONSchema } from 'genkit'; +import { GenkitError, z, type JSONSchema } from 'genkit'; import { GenerationCommonConfigDescriptions, GenerationCommonConfigSchema, + modelRef as createModelRef, getBasicUsageStats, - modelRef, type CandidateData, type MediaPart, type MessageData, @@ -57,6 +57,7 @@ import { type ToolResponsePart, } from 'genkit/model'; import { downloadRequestMedia } from 'genkit/model/middleware'; +import { model } from 'genkit/plugin'; import { runInNewSpan } from 'genkit/tracing'; import { getApiKeyFromEnvVar, getGenkitClientHeader } from './common'; import { handleCacheIfNeeded } from './context-caching'; @@ -276,7 +277,7 @@ export const GeminiTtsConfigSchema = GeminiConfigSchema.extend({ .optional(), }).passthrough(); -export const gemini10Pro = modelRef({ +export const gemini10Pro = createModelRef({ name: 'googleai/gemini-1.0-pro', info: { label: 'Google AI - Gemini Pro', @@ -293,7 +294,7 @@ export const gemini10Pro = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini15Pro = modelRef({ +export const gemini15Pro = createModelRef({ name: 'googleai/gemini-1.5-pro', info: { label: 'Google AI - Gemini 1.5 Pro', @@ -314,7 +315,7 @@ export const gemini15Pro = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini15Flash = modelRef({ +export const gemini15Flash = createModelRef({ name: 'googleai/gemini-1.5-flash', info: { label: 'Google AI - Gemini 1.5 Flash', @@ -337,7 +338,7 @@ export const gemini15Flash = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini15Flash8b = modelRef({ +export const gemini15Flash8b = createModelRef({ name: 'googleai/gemini-1.5-flash-8b', info: { label: 'Google AI - Gemini 1.5 Flash', @@ -354,7 +355,7 @@ export const gemini15Flash8b = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini20Flash = modelRef({ +export const gemini20Flash = createModelRef({ name: 'googleai/gemini-2.0-flash', info: { label: 'Google AI - Gemini 2.0 Flash', @@ -371,7 +372,7 @@ export const gemini20Flash = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini20FlashExp = modelRef({ +export const gemini20FlashExp = createModelRef({ name: 'googleai/gemini-2.0-flash-exp', info: { label: 'Google AI - Gemini 2.0 Flash (Experimental)', @@ -388,7 +389,7 @@ export const gemini20FlashExp = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini20FlashLite = modelRef({ +export const gemini20FlashLite = createModelRef({ name: 'googleai/gemini-2.0-flash-lite', info: { label: 'Google AI - Gemini 2.0 Flash Lite', @@ -405,7 +406,7 @@ export const gemini20FlashLite = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini20ProExp0205 = modelRef({ +export const gemini20ProExp0205 = createModelRef({ name: 'googleai/gemini-2.0-pro-exp-02-05', info: { label: 'Google AI - Gemini 2.0 Pro Exp 02-05', @@ -422,7 +423,7 @@ export const gemini20ProExp0205 = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25FlashPreview0417 = modelRef({ +export const gemini25FlashPreview0417 = createModelRef({ name: 'googleai/gemini-2.5-flash-preview-04-17', info: { label: 'Google AI - Gemini 2.5 Flash Preview 04-17', @@ -439,7 +440,7 @@ export const gemini25FlashPreview0417 = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25FlashPreviewTts = modelRef({ +export const gemini25FlashPreviewTts = createModelRef({ name: 'googleai/gemini-2.5-flash-preview-tts', info: { label: 'Google AI - Gemini 2.5 Flash Preview TTS', @@ -456,7 +457,7 @@ export const gemini25FlashPreviewTts = modelRef({ configSchema: GeminiTtsConfigSchema, }); -export const gemini25ProExp0325 = modelRef({ +export const gemini25ProExp0325 = createModelRef({ name: 'googleai/gemini-2.5-pro-exp-03-25', info: { label: 'Google AI - Gemini 2.5 Pro Exp 03-25', @@ -473,7 +474,7 @@ export const gemini25ProExp0325 = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25ProPreview0325 = modelRef({ +export const gemini25ProPreview0325 = createModelRef({ name: 'googleai/gemini-2.5-pro-preview-03-25', info: { label: 'Google AI - Gemini 2.5 Pro Preview 03-25', @@ -490,7 +491,7 @@ export const gemini25ProPreview0325 = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25ProPreviewTts = modelRef({ +export const gemini25ProPreviewTts = createModelRef({ name: 'googleai/gemini-2.5-pro-preview-tts', info: { label: 'Google AI - Gemini 2.5 Pro Preview TTS', @@ -507,7 +508,7 @@ export const gemini25ProPreviewTts = modelRef({ configSchema: GeminiTtsConfigSchema, }); -export const gemini25Pro = modelRef({ +export const gemini25Pro = createModelRef({ name: 'googleai/gemini-2.5-pro', info: { label: 'Google AI - Gemini 2.5 Pro', @@ -524,7 +525,7 @@ export const gemini25Pro = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25Flash = modelRef({ +export const gemini25Flash = createModelRef({ name: 'googleai/gemini-2.5-flash', info: { label: 'Google AI - Gemini 2.5 Flash', @@ -541,7 +542,7 @@ export const gemini25Flash = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemini25FlashLite = modelRef({ +export const gemini25FlashLite = createModelRef({ name: 'googleai/gemini-2.5-flash-lite', info: { label: 'Google AI - Gemini 2.5 Flash Lite', @@ -558,7 +559,7 @@ export const gemini25FlashLite = modelRef({ configSchema: GeminiConfigSchema, }); -export const gemma312bit = modelRef({ +export const gemma312bit = createModelRef({ name: 'googleai/gemma-3-12b-it', info: { label: 'Google AI - Gemma 3 12B', @@ -575,7 +576,7 @@ export const gemma312bit = modelRef({ configSchema: GeminiGemmaConfigSchema, }); -export const gemma31bit = modelRef({ +export const gemma31bit = createModelRef({ name: 'googleai/gemma-3-1b-it', info: { label: 'Google AI - Gemma 3 1B', @@ -592,7 +593,7 @@ export const gemma31bit = modelRef({ configSchema: GeminiGemmaConfigSchema, }); -export const gemma327bit = modelRef({ +export const gemma327bit = createModelRef({ name: 'googleai/gemma-3-27b-it', info: { label: 'Google AI - Gemma 3 27B', @@ -609,7 +610,7 @@ export const gemma327bit = modelRef({ configSchema: GeminiGemmaConfigSchema, }); -export const gemma34bit = modelRef({ +export const gemma34bit = createModelRef({ name: 'googleai/gemma-3-4b-it', info: { label: 'Google AI - Gemma 3 4B', @@ -626,7 +627,7 @@ export const gemma34bit = modelRef({ configSchema: GeminiGemmaConfigSchema, }); -export const gemma3ne4bit = modelRef({ +export const gemma3ne4bit = createModelRef({ name: 'googleai/gemma-3n-e4b-it', info: { label: 'Google AI - Gemma 3n E4B', @@ -666,7 +667,7 @@ export const SUPPORTED_GEMINI_MODELS = { 'gemma-3n-e4b-it': gemma3ne4bit, }; -export const GENERIC_GEMINI_MODEL = modelRef({ +export const GENERIC_GEMINI_MODEL = createModelRef({ name: 'googleai/gemini', configSchema: GeminiConfigSchema, info: { @@ -714,7 +715,7 @@ export function gemini( options: GeminiConfig = {} ): ModelReference { const nearestModel = nearestGeminiModelRef(version); - return modelRef({ + return createModelRef({ name: `googleai/${version}`, config: options, configSchema: GeminiConfigSchema, @@ -1118,7 +1119,6 @@ export function cleanSchema(schema: JSONSchema): JSONSchema { * Defines a new GoogleAI model. */ export function defineGoogleAIModel({ - ai, name, apiKey: apiKeyOption, apiVersion, @@ -1127,7 +1127,6 @@ export function defineGoogleAIModel({ defaultConfig, debugTraces, }: { - ai: Genkit; name: string; apiKey?: string | false; apiVersion?: string; @@ -1154,9 +1153,9 @@ export function defineGoogleAIModel({ ? name.substring('googleai/'.length) : name; - const model: ModelReference = + const modelRef: ModelReference = SUPPORTED_GEMINI_MODELS[apiModelName] ?? - modelRef({ + createModelRef({ name: `googleai/${apiModelName}`, info: { label: `Google AI - ${apiModelName}`, @@ -1173,7 +1172,7 @@ export function defineGoogleAIModel({ }); const middleware: ModelMiddleware[] = []; - if (model.info?.supports?.media) { + if (modelRef.info?.supports?.media) { // the gemini api doesn't support downloading media from http(s) middleware.push( downloadRequestMedia({ @@ -1199,12 +1198,11 @@ export function defineGoogleAIModel({ ); } - return ai.defineModel( + return model( { - apiVersion: 'v2', - name: model.name, - ...model.info, - configSchema: model.configSchema, + name: modelRef.name, + ...modelRef.info, + configSchema: GeminiConfigSchema, use: middleware, }, async (request, { streamingRequested, sendChunk, abortSignal }) => { @@ -1228,7 +1226,7 @@ export function defineGoogleAIModel({ // systemInstructions to be provided as a separate input. The first // message detected with role=system will be used for systemInstructions. let systemInstruction: GeminiMessage | undefined = undefined; - if (model.info?.supports?.systemRole) { + if (modelRef.info?.supports?.systemRole) { const systemMessage = messages.find((m) => m.role === 'system'); if (systemMessage) { messages.splice(messages.indexOf(systemMessage), 1); @@ -1256,10 +1254,11 @@ export function defineGoogleAIModel({ if (codeExecutionFromConfig) { tools.push({ - codeExecution: - request.config.codeExecution === true + codeExecution: requestConfig.codeExecution + ? requestConfig.codeExecution === true ? {} - : request.config.codeExecution, + : requestConfig.codeExecution + : {}, }); } @@ -1306,7 +1305,7 @@ export function defineGoogleAIModel({ generationConfig.responseSchema = cleanSchema(request.output.schema); } - const msg = toGeminiMessage(messages[messages.length - 1], model); + const msg = toGeminiMessage(messages[messages.length - 1], modelRef); const fromJSONModeScopedGeminiCandidate = ( candidate: GeminiCandidate @@ -1321,11 +1320,11 @@ export function defineGoogleAIModel({ toolConfig, history: messages .slice(0, -1) - .map((message) => toGeminiMessage(message, model)), + .map((message) => toGeminiMessage(message, modelRef)), safetySettings: safetySettingsFromConfig, } as StartChatParams; const modelVersion = (versionFromConfig || - model.version || + modelRef.version || apiModelName) as string; const cacheConfigDetails = extractCacheConfig(request); @@ -1430,7 +1429,6 @@ export function defineGoogleAIModel({ // API params as for input. return debugTraces ? await runInNewSpan( - ai.registry, { metadata: { name: streamingRequested ? 'sendMessageStream' : 'sendMessage', diff --git a/js/plugins/googleai/src/imagen.ts b/js/plugins/googleai/src/imagen.ts index d7d6c39709..3026776930 100644 --- a/js/plugins/googleai/src/imagen.ts +++ b/js/plugins/googleai/src/imagen.ts @@ -14,15 +14,16 @@ * limitations under the License. */ -import { GenkitError, MessageData, z, type Genkit } from 'genkit'; +import { GenkitError, MessageData, z } from 'genkit'; import { + modelRef as createModelRef, getBasicUsageStats, - modelRef, type GenerateRequest, type ModelAction, type ModelInfo, type ModelReference, } from 'genkit/model'; +import { model } from 'genkit/plugin'; import { getApiKeyFromEnvVar } from './common.js'; import { predictModel } from './predict.js'; @@ -109,7 +110,6 @@ export const GENERIC_IMAGEN_INFO = { } as ModelInfo; export function defineImagenModel( - ai: Genkit, name: string, apiKey?: string | false ): ModelAction { @@ -125,7 +125,7 @@ export function defineImagenModel( } } const modelName = `googleai/${name}`; - const model: ModelReference = modelRef({ + const modelRef: ModelReference = createModelRef({ name: modelName, info: { ...GENERIC_IMAGEN_INFO, @@ -134,10 +134,10 @@ export function defineImagenModel( configSchema: ImagenConfigSchema, }); - return ai.defineModel( + return model( { name: modelName, - ...model.info, + ...modelRef.info, configSchema: ImagenConfigSchema, }, async (request) => { @@ -153,7 +153,7 @@ export function defineImagenModel( ImagenInstance, ImagenPrediction, ImagenParameters - >(model.version || name, apiKey as string, 'predict'); + >(modelRef.version || name, apiKey as string, 'predict'); const response = await predictClient([instance], toParameters(request)); if (!response.predictions || response.predictions.length == 0) { diff --git a/js/plugins/googleai/src/index.ts b/js/plugins/googleai/src/index.ts index 52cb48a880..219fbae62b 100644 --- a/js/plugins/googleai/src/index.ts +++ b/js/plugins/googleai/src/index.ts @@ -20,13 +20,16 @@ import { modelActionMetadata, type ActionMetadata, type EmbedderReference, - type Genkit, type ModelReference, type z, } from 'genkit'; import { logger } from 'genkit/logging'; import { modelRef } from 'genkit/model'; -import { genkitPlugin, type GenkitPlugin } from 'genkit/plugin'; +import { + ResolvableAction, + genkitPluginV2, + type GenkitPluginV2, +} from 'genkit/plugin'; import type { ActionType } from 'genkit/registry'; import { getApiKeyFromEnvVar } from './common.js'; import { @@ -112,8 +115,11 @@ export interface PluginOptions { experimental_debugTraces?: boolean; } -async function initializer(ai: Genkit, options?: PluginOptions) { +async function initializer( + options?: PluginOptions +): Promise { let apiVersions = ['v1']; + const actions: ResolvableAction[] = []; if (options?.apiVersion) { if (Array.isArray(options?.apiVersion)) { @@ -124,30 +130,34 @@ async function initializer(ai: Genkit, options?: PluginOptions) { } if (apiVersions.includes('v1beta')) { - Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) => - defineGoogleAIModel({ - ai, - name, - apiKey: options?.apiKey, - apiVersion: 'v1beta', - baseUrl: options?.baseUrl, - debugTraces: options?.experimental_debugTraces, - }) + actions.push( + ...Object.keys(SUPPORTED_GEMINI_MODELS).map((name) => + defineGoogleAIModel({ + name, + apiKey: options?.apiKey, + apiVersion: 'v1beta', + baseUrl: options?.baseUrl, + debugTraces: options?.experimental_debugTraces, + }) + ) ); } if (apiVersions.includes('v1')) { - Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) => - defineGoogleAIModel({ - ai, - name, - apiKey: options?.apiKey, - apiVersion: undefined, - baseUrl: options?.baseUrl, - debugTraces: options?.experimental_debugTraces, - }) + actions.push( + ...Object.keys(SUPPORTED_GEMINI_MODELS).map((name) => + defineGoogleAIModel({ + name, + apiKey: options?.apiKey, + apiVersion: undefined, + baseUrl: options?.baseUrl, + debugTraces: options?.experimental_debugTraces, + }) + ) ); - Object.keys(EMBEDDER_MODELS).forEach((name) => - defineGoogleAIEmbedder(ai, name, { apiKey: options?.apiKey }) + actions.push( + ...Object.keys(EMBEDDER_MODELS).map((name) => + defineGoogleAIEmbedder(name, { apiKey: options?.apiKey }) + ) ); } @@ -160,50 +170,55 @@ async function initializer(ai: Genkit, options?: PluginOptions) { modelOrRef.name.split('/')[1]; const modelRef = typeof modelOrRef === 'string' ? gemini(modelOrRef) : modelOrRef; - defineGoogleAIModel({ - ai, - name: modelName, - apiKey: options?.apiKey, - baseUrl: options?.baseUrl, - info: { - ...modelRef.info, - label: `Google AI - ${modelName}`, - }, - debugTraces: options?.experimental_debugTraces, - }); + actions.push( + defineGoogleAIModel({ + name: modelName, + apiKey: options?.apiKey, + baseUrl: options?.baseUrl, + info: { + ...modelRef.info, + label: `Google AI - ${modelName}`, + }, + debugTraces: options?.experimental_debugTraces, + }) + ); } } + + return actions; } async function resolver( - ai: Genkit, actionType: ActionType, actionName: string, options?: PluginOptions -) { +): Promise { if (actionType === 'embedder') { - resolveEmbedder(ai, actionName, options); + return resolveEmbedder(actionName, options); } else if (actionName.startsWith('veo')) { // we do it this way because the request may come in for // action type 'model' and action name 'veo-...'. That case should // be a noop. It's just the order or model lookup. if (actionType === 'background-model') { - defineVeoModel(ai, actionName, options?.apiKey); + return defineVeoModel(actionName, options?.apiKey); } } else if (actionType === 'model') { - resolveModel(ai, actionName, options); + return resolveModel(actionName, options); } + + return undefined; } -function resolveModel(ai: Genkit, actionName: string, options?: PluginOptions) { +function resolveModel( + actionName: string, + options?: PluginOptions +): ResolvableAction | undefined { if (actionName.startsWith('imagen')) { - defineImagenModel(ai, actionName, options?.apiKey); - return; + return defineImagenModel(actionName, options?.apiKey); } const modelRef = gemini(actionName); - defineGoogleAIModel({ - ai, + return defineGoogleAIModel({ name: modelRef.name, apiKey: options?.apiKey, baseUrl: options?.baseUrl, @@ -216,11 +231,10 @@ function resolveModel(ai: Genkit, actionName: string, options?: PluginOptions) { } function resolveEmbedder( - ai: Genkit, actionName: string, options?: PluginOptions -) { - defineGoogleAIEmbedder(ai, `googleai/${actionName}`, { +): ResolvableAction | undefined { + return defineGoogleAIEmbedder(`googleai/${actionName}`, { apiKey: options?.apiKey, }); } @@ -328,23 +342,23 @@ async function listActions(options?: PluginOptions): Promise { /** * Google Gemini Developer API plugin. */ -export function googleAIPlugin(options?: PluginOptions): GenkitPlugin { +export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 { let listActionsCache; - return genkitPlugin( - 'googleai', - async (ai: Genkit) => await initializer(ai, options), - async (ai: Genkit, actionType: ActionType, actionName: string) => - await resolver(ai, actionType, actionName, options), - async () => { + return genkitPluginV2({ + name: 'googleai', + init: async () => await initializer(options), + resolve: async (actionType: ActionType, actionName: string) => + await resolver(actionType, actionName, options), + list: async () => { if (listActionsCache) return listActionsCache; listActionsCache = await listActions(options); return listActionsCache; - } - ); + }, + }); } export type GoogleAIPlugin = { - (params?: PluginOptions): GenkitPlugin; + (params?: PluginOptions): GenkitPluginV2; model( name: keyof typeof SUPPORTED_GEMINI_MODELS | (`gemini-${string}` & {}), config?: z.infer diff --git a/js/plugins/googleai/src/veo.ts b/js/plugins/googleai/src/veo.ts index b35c87a377..9fb9aa07b0 100644 --- a/js/plugins/googleai/src/veo.ts +++ b/js/plugins/googleai/src/veo.ts @@ -14,20 +14,15 @@ * limitations under the License. */ -import { - GenerateResponseData, - GenkitError, - Operation, - z, - type Genkit, -} from 'genkit'; +import { GenerateResponseData, GenkitError, Operation, z } from 'genkit'; import { BackgroundModelAction, - modelRef, + modelRef as createModelRef, type GenerateRequest, type ModelInfo, type ModelReference, } from 'genkit/model'; +import { backgroundModel } from 'genkit/plugin'; import { getApiKeyFromEnvVar } from './common.js'; import { Operation as ApiOperation, checkOp, predictModel } from './predict.js'; @@ -127,7 +122,6 @@ export const GENERIC_VEO_INFO = { } as ModelInfo; export function defineVeoModel( - ai: Genkit, name: string, apiKey?: string | false ): BackgroundModelAction { @@ -143,7 +137,7 @@ export function defineVeoModel( } } const modelName = `googleai/${name}`; - const model: ModelReference = modelRef({ + const modelRef: ModelReference = createModelRef({ name: modelName, info: { ...GENERIC_VEO_INFO, @@ -152,9 +146,9 @@ export function defineVeoModel( configSchema: VeoConfigSchema, }); - return ai.defineBackgroundModel({ + return backgroundModel({ name: modelName, - ...model.info, + ...modelRef.info, configSchema: VeoConfigSchema, async start(request) { const instance: VeoInstance = { @@ -169,7 +163,7 @@ export function defineVeoModel( VeoInstance, ApiOperation, VeoParameters - >(model.version || name, apiKey as string, 'predictLongRunning'); + >(modelRef.version || name, apiKey as string, 'predictLongRunning'); const response = await predictClient([instance], toParameters(request)); return toGenkitOp(response);