Skip to content

Commit fc0f970

Browse files
committed
fix(plugins/google-genai): address feedback
1 parent 14a0263 commit fc0f970

File tree

7 files changed

+54
-49
lines changed

7 files changed

+54
-49
lines changed

js/plugins/google-genai/src/googleai/embedder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function defineEmbedder(
141141
configSchema: ref.configSchema,
142142
info: ref.info,
143143
},
144-
async (request, _) => {
144+
async (request) => {
145145
const embedApiKey = calculateApiKey(
146146
pluginOptions?.apiKey,
147147
request.options?.apiKey

js/plugins/google-genai/src/googleai/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@
1515
*/
1616

1717
import { ActionMetadata, EmbedderReference, ModelReference, z } from 'genkit';
18+
import { logger } from 'genkit/logging';
1819
import {
1920
GenkitPluginV2,
2021
ResolvableAction,
2122
genkitPluginV2,
2223
} from 'genkit/plugin';
23-
import type { ActionType } from 'genkit/registry';
24+
import { ActionType } from 'genkit/registry';
2425

2526
// These are namespaced because they all intentionally have
2627
// functions of the same name with the same arguments.
2728
// (All exports from these files are used here)
28-
import { logger } from 'genkit/logging';
29-
import { extractErrMsg } from '../common/utils.js';
30-
import { listModels } from './client.js';
3129
import * as embedder from './embedder.js';
3230
import * as gemini from './gemini.js';
3331
import * as imagen from './imagen.js';
32+
import * as veo from './veo.js';
33+
34+
import { extractErrMsg } from '../common/utils.js';
35+
import { listModels } from './client.js';
3436
import { GoogleAIPluginOptions } from './types.js';
3537
import { calculateApiKey } from './utils.js';
36-
import * as veo from './veo.js';
3738

3839
export { type EmbeddingConfig } from './embedder.js';
3940
export { type GeminiConfig, type GeminiTtsConfig } from './gemini.js';
@@ -59,7 +60,7 @@ async function resolver(
5960
switch (actionType) {
6061
case 'model':
6162
if (veo.isVeoModelName(actionName)) {
62-
// no-op
63+
// no-op (not gemini)
6364
} else if (imagen.isImagenModelName(actionName)) {
6465
return imagen.defineModel(actionName, options);
6566
} else {
@@ -111,7 +112,7 @@ export function googleAIPlugin(
111112
return genkitPluginV2({
112113
name: 'googleai',
113114
init: async () => await initializer(options),
114-
resolve: async (actionType, actionName) =>
115+
resolve: async (actionType: ActionType, actionName: string) =>
115116
await resolver(actionType, actionName, options || {}),
116117
list: async () => {
117118
if (listActionsCache) return listActionsCache;

js/plugins/google-genai/src/googleai/veo.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
type ModelReference,
3030
} from 'genkit/model';
3131
import { backgroundModel } from 'genkit/plugin';
32-
3332
import { veoCheckOperation, veoPredict } from './client.js';
3433
import {
3534
ClientOptions,

js/plugins/google-genai/src/vertexai/embedder.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ export const KNOWN_MODELS = {
108108
supports: { input: ['text'] },
109109
}),
110110
} as const;
111-
export type KnownModels = keyof typeof KNOWN_MODELS;
112-
export type EmbedderModelName = `embedder=${string}`;
113-
export function isEmbedderModelName(
114-
value?: string
115-
): value is EmbedderModelName {
116-
return !!value?.includes('embedding');
117-
}
118111

119112
export function createEmbedderRef(
120113
version: string,
@@ -165,7 +158,7 @@ export function defineKnownModels(
165158
export function defineEmbedder(
166159
name: string,
167160
clientOptions: ClientOptions,
168-
pluginOptions?: VertexPluginOptions
161+
_?: VertexPluginOptions
169162
): EmbedderAction<any> {
170163
const ref = createEmbedderRef(name);
171164

@@ -175,7 +168,7 @@ export function defineEmbedder(
175168
configSchema: ref.configSchema,
176169
info: ref.info!,
177170
},
178-
async (request, options) => {
171+
async (request) => {
179172
const embedContentRequest: EmbedContentRequest = {
180173
instances: request.input.map((doc: Document) =>
181174
toEmbeddingInstance(ref, doc, request.options)

js/plugins/google-genai/src/vertexai/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
import { EmbedderReference, ModelReference, z } from 'genkit';
2424
import { GenkitPluginV2, genkitPluginV2 } from 'genkit/plugin';
25+
import { ActionType } from 'genkit/registry';
2526

2627
import * as embedder from './embedder.js';
2728
import * as gemini from './gemini.js';
2829
import * as imagen from './imagen.js';
2930
import * as lyria from './lyria.js';
3031
import * as veo from './veo.js';
3132

32-
import { ActionType } from 'genkit/registry';
3333
import { listModels } from './client.js';
3434
import { VertexPluginOptions } from './types.js';
3535
import { getDerivedOptions } from './utils.js';
@@ -45,6 +45,8 @@ async function initializer(pluginOptions?: VertexPluginOptions) {
4545
const clientOptions = await getDerivedOptions(pluginOptions);
4646

4747
return [
48+
...veo.defineKnownModels(clientOptions, pluginOptions),
49+
...lyria.defineKnownModels(clientOptions, pluginOptions),
4850
...imagen.defineKnownModels(clientOptions, pluginOptions),
4951
...gemini.defineKnownModels(clientOptions, pluginOptions),
5052
...embedder.defineKnownModels(clientOptions, pluginOptions),
@@ -59,25 +61,37 @@ async function resolver(
5961
const clientOptions = await getDerivedOptions(pluginOptions);
6062
switch (actionType) {
6163
case 'model':
62-
if (imagen.isImagenModelName(actionName)) {
64+
if (lyria.isLyriaModelName(actionName)) {
65+
return lyria.defineModel(actionName, clientOptions, pluginOptions);
66+
} else if (imagen.isImagenModelName(actionName)) {
6367
return imagen.defineModel(actionName, clientOptions, pluginOptions);
68+
} else if (veo.isVeoModelName(actionName)) {
69+
// no-op (not gemini)
6470
} else {
6571
return gemini.defineModel(actionName, clientOptions, pluginOptions);
6672
}
73+
break;
74+
case 'background-model':
75+
if (veo.isVeoModelName(actionName)) {
76+
return veo.defineModel(actionName, clientOptions, pluginOptions);
77+
}
78+
break;
6779
case 'embedder':
6880
return embedder.defineEmbedder(actionName, clientOptions, pluginOptions);
69-
default:
70-
return undefined;
7181
}
82+
83+
return undefined;
7284
}
7385

7486
async function listActions(options?: VertexPluginOptions) {
75-
const clientOptions = await getDerivedOptions(options);
7687
try {
88+
const clientOptions = await getDerivedOptions(options);
7789
const models = await listModels(clientOptions);
7890
return [
7991
...gemini.listActions(models),
8092
...imagen.listActions(models),
93+
...lyria.listActions(models),
94+
...veo.listActions(models),
8195
// We don't list embedders here
8296
];
8397
} catch (e: unknown) {

js/plugins/google-genai/tests/googleai/veo_test.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { Operation } from 'genkit';
1919
import { GenerateRequest } from 'genkit/model';
2020
import { afterEach, beforeEach, describe, it } from 'node:test';
2121
import * as sinon from 'sinon';
22-
2322
import { getGenkitClientHeader } from '../../src/common/utils.js';
2423
import { getGoogleAIUrl } from '../../src/googleai/client.js';
2524
import { VeoOperation, VeoPredictRequest } from '../../src/googleai/types.js';
@@ -236,8 +235,8 @@ describe('Google AI Veo', () => {
236235
};
237236
mockFetchResponse(mockOp);
238237

239-
const modelAction = captureModelRunner({ apiKey: defaultApiKey });
240-
const result = await modelAction.start(request);
238+
const { start } = captureModelRunner({ apiKey: defaultApiKey });
239+
const result = await start(request);
241240

242241
sinon.assert.calledOnce(fetchStub);
243242
const fetchArgs = fetchStub.lastCall.args;
@@ -276,12 +275,12 @@ describe('Google AI Veo', () => {
276275
const apiVersion = 'v1test';
277276
const baseUrl = 'https://test.example.com';
278277

279-
const modelAction = captureModelRunner({
278+
const { start } = captureModelRunner({
280279
apiKey: defaultApiKey,
281280
apiVersion,
282281
baseUrl,
283282
});
284-
await modelAction.start(request);
283+
await start(request);
285284

286285
sinon.assert.calledOnce(fetchStub);
287286
const fetchArgs = fetchStub.lastCall.args;
@@ -298,8 +297,8 @@ describe('Google AI Veo', () => {
298297
envStub.value({ GOOGLE_API_KEY: envKey });
299298
mockFetchResponse({ name: 'operations/start789', done: false });
300299

301-
const modelAction = captureModelRunner({ apiKey: undefined });
302-
await modelAction.start(request);
300+
const { start } = captureModelRunner({ apiKey: undefined });
301+
await start(request);
303302

304303
sinon.assert.calledOnce(fetchStub);
305304
const fetchArgs = fetchStub.lastCall.args;
@@ -310,9 +309,9 @@ describe('Google AI Veo', () => {
310309
const errorBody = { error: { message: 'Invalid argument', code: 400 } };
311310
mockFetchResponse(errorBody, 400);
312311

313-
const modelAction = captureModelRunner({ apiKey: defaultApiKey });
312+
const { start } = captureModelRunner({ apiKey: defaultApiKey });
314313
await assert.rejects(
315-
modelAction.start(request),
314+
start(request),
316315
/Error fetching from .*models\/veo-test-model:predictLongRunning.* Invalid argument/
317316
);
318317
});
@@ -334,8 +333,8 @@ describe('Google AI Veo', () => {
334333
};
335334
mockFetchResponse(mockResponse);
336335

337-
const modelAction = captureModelRunner({ apiKey: defaultApiKey });
338-
const result = await modelAction.check(pendingOp);
336+
const { check } = captureModelRunner({ apiKey: defaultApiKey });
337+
const result = await check(pendingOp);
339338

340339
sinon.assert.calledOnce(fetchStub);
341340
const fetchArgs = fetchStub.lastCall.args;
@@ -365,12 +364,12 @@ describe('Google AI Veo', () => {
365364
const apiVersion = 'v1test';
366365
const baseUrl = 'https://test.example.com';
367366

368-
const modelAction = captureModelRunner({
367+
const { check } = captureModelRunner({
369368
apiKey: defaultApiKey,
370369
apiVersion,
371370
baseUrl,
372371
});
373-
await modelAction.check(pendingOp);
372+
await check(pendingOp);
374373

375374
sinon.assert.calledOnce(fetchStub);
376375
const fetchArgs = fetchStub.lastCall.args;
@@ -385,9 +384,9 @@ describe('Google AI Veo', () => {
385384
const errorBody = { error: { message: 'Not found', code: 404 } };
386385
mockFetchResponse(errorBody, 404);
387386

388-
const modelAction = captureModelRunner({ apiKey: defaultApiKey });
387+
const { check } = captureModelRunner({ apiKey: defaultApiKey });
389388
await assert.rejects(
390-
modelAction.check(pendingOp),
389+
check(pendingOp),
391390
/Error fetching from .*operations\/check123.* Not found/
392391
);
393392
});

js/plugins/google-genai/tests/vertexai/veo_test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { GenerateRequest } from 'genkit/model';
2020
import { GoogleAuth } from 'google-auth-library';
2121
import { afterEach, beforeEach, describe, it } from 'node:test';
2222
import * as sinon from 'sinon';
23-
2423
import { getGenkitClientHeader } from '../../src/common/utils.js';
2524
import { getVertexAIUrl } from '../../src/vertexai/client.js';
2625
import {
@@ -134,8 +133,8 @@ describe('Vertex AI Veo', () => {
134133
};
135134
mockFetchResponse(mockOp);
136135

137-
const modelAction = captureModelRunner(defaultRegionalClientOptions);
138-
const result = await modelAction.start(request);
136+
const { start } = captureModelRunner(defaultRegionalClientOptions);
137+
const result = await start(request);
139138

140139
sinon.assert.calledOnce(fetchStub);
141140
const fetchArgs = fetchStub.lastCall.args;
@@ -168,9 +167,9 @@ describe('Vertex AI Veo', () => {
168167
const errorBody = { error: { message: 'Invalid arg', code: 400 } };
169168
mockFetchResponse(errorBody, 400);
170169

171-
const modelAction = captureModelRunner(defaultRegionalClientOptions);
170+
const { start } = captureModelRunner(defaultRegionalClientOptions);
172171
await assert.rejects(
173-
modelAction.start(request),
172+
start(request),
174173
/Error fetching from .*predictLongRunning.* Invalid arg/
175174
);
176175
});
@@ -184,8 +183,8 @@ describe('Vertex AI Veo', () => {
184183
...defaultRegionalClientOptions,
185184
signal: abortSignal,
186185
};
187-
const modelAction = captureModelRunner(clientOptionsWithSignal);
188-
await modelAction.start(request);
186+
const { start } = captureModelRunner(clientOptionsWithSignal);
187+
await start(request);
189188

190189
sinon.assert.calledOnce(fetchStub);
191190
const fetchOptions = fetchStub.lastCall.args[1];
@@ -220,8 +219,8 @@ describe('Vertex AI Veo', () => {
220219
};
221220
mockFetchResponse(mockResponse);
222221

223-
const modelAction = captureModelRunner(defaultRegionalClientOptions);
224-
const result = await modelAction.check(pendingOp);
222+
const { check } = captureModelRunner(defaultRegionalClientOptions);
223+
const result = await check(pendingOp);
225224

226225
sinon.assert.calledOnce(fetchStub);
227226
const fetchArgs = fetchStub.lastCall.args;
@@ -252,9 +251,9 @@ describe('Vertex AI Veo', () => {
252251
const errorBody = { error: { message: 'Not found', code: 404 } };
253252
mockFetchResponse(errorBody, 404);
254253

255-
const modelAction = captureModelRunner(defaultRegionalClientOptions);
254+
const { check } = captureModelRunner(defaultRegionalClientOptions);
256255
await assert.rejects(
257-
modelAction.check(pendingOp),
256+
check(pendingOp),
258257
/Error fetching from .*fetchPredictOperation.* Not found/
259258
);
260259
});

0 commit comments

Comments
 (0)