Skip to content

Commit 7068764

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

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
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: 7 additions & 6 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';
@@ -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) {

0 commit comments

Comments
 (0)