Skip to content

Commit 18f0670

Browse files
committed
refactor(plugins/googleai): revert adding prefixes
1 parent db7a169 commit 18f0670

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

js/plugins/googleai/src/embedder.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ export const geminiEmbedding001 = embedderRef({
9797
});
9898

9999
export const SUPPORTED_MODELS = {
100-
'googleai/embedding-001': textEmbeddingGecko001,
101-
'googleai/text-embedding-004': textEmbedding004,
102-
'googleai/gemini-embedding-001': geminiEmbedding001,
100+
'embedding-001': textEmbeddingGecko001,
101+
'text-embedding-004': textEmbedding004,
102+
'gemini-embedding-001': geminiEmbedding001,
103103
};
104104

105105
export function defineGoogleAIEmbedder(
@@ -116,22 +116,24 @@ export function defineGoogleAIEmbedder(
116116
'For more details see https://genkit.dev/docs/plugins/google-genai'
117117
);
118118
}
119+
// Extract the bare model name for lookup and API calls
120+
const apiModelName = name.startsWith('googleai/')
121+
? name.substring('googleai/'.length)
122+
: name;
123+
119124
const embedderReference: EmbedderReference =
120-
SUPPORTED_MODELS[name] ??
125+
SUPPORTED_MODELS[apiModelName] ??
121126
embedderRef({
122127
name: name,
123128
configSchema: GeminiEmbeddingConfigSchema,
124129
info: {
125130
dimensions: 768,
126-
label: `Google AI - ${name}`,
131+
label: `Google AI - ${apiModelName}`,
127132
supports: {
128133
input: ['text', 'image', 'video'],
129134
},
130135
},
131136
});
132-
const apiModelName = embedderReference.name.startsWith('googleai/')
133-
? embedderReference.name.substring('googleai/'.length)
134-
: embedderReference.name;
135137
return embedder(
136138
{
137139
name: embedderReference.name,

js/plugins/googleai/src/gemini.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
import { downloadRequestMedia } from 'genkit/model/middleware';
6060
import { model } from 'genkit/plugin';
6161
import { runInNewSpan } from 'genkit/tracing';
62-
import { getApiKeyFromEnvVar, getGenkitClientHeader } from './common.js';
62+
import { getApiKeyFromEnvVar, getGenkitClientHeader } from './common';
6363
import { handleCacheIfNeeded } from './context-caching';
6464
import { extractCacheConfig } from './context-caching/utils';
6565

@@ -645,26 +645,26 @@ export const gemma3ne4bit = modelRef({
645645
});
646646

647647
export const SUPPORTED_GEMINI_MODELS = {
648-
'googleai/gemini-1.5-pro': gemini15Pro,
649-
'googleai/gemini-1.5-flash': gemini15Flash,
650-
'googleai/gemini-1.5-flash-8b': gemini15Flash8b,
651-
'googleai/gemini-2.0-pro-exp-02-05': gemini20ProExp0205,
652-
'googleai/gemini-2.0-flash': gemini20Flash,
653-
'googleai/gemini-2.0-flash-lite': gemini20FlashLite,
654-
'googleai/gemini-2.0-flash-exp': gemini20FlashExp,
655-
'googleai/gemini-2.5-pro-exp-03-25': gemini25ProExp0325,
656-
'googleai/gemini-2.5-pro-preview-03-25': gemini25ProPreview0325,
657-
'googleai/gemini-2.5-pro-preview-tts': gemini25ProPreviewTts,
658-
'googleai/gemini-2.5-flash-preview-04-17': gemini25FlashPreview0417,
659-
'googleai/gemini-2.5-flash-preview-tts': gemini25FlashPreviewTts,
660-
'googleai/gemini-2.5-flash': gemini25Flash,
661-
'googleai/gemini-2.5-flash-lite': gemini25FlashLite,
662-
'googleai/gemini-2.5-pro': gemini25Pro,
663-
'googleai/gemma-3-12b-it': gemma312bit,
664-
'googleai/gemma-3-1b-it': gemma31bit,
665-
'googleai/gemma-3-27b-it': gemma327bit,
666-
'googleai/gemma-3-4b-it': gemma34bit,
667-
'googleai/gemma-3n-e4b-it': gemma3ne4bit,
648+
'gemini-1.5-pro': gemini15Pro,
649+
'gemini-1.5-flash': gemini15Flash,
650+
'gemini-1.5-flash-8b': gemini15Flash8b,
651+
'gemini-2.0-pro-exp-02-05': gemini20ProExp0205,
652+
'gemini-2.0-flash': gemini20Flash,
653+
'gemini-2.0-flash-lite': gemini20FlashLite,
654+
'gemini-2.0-flash-exp': gemini20FlashExp,
655+
'gemini-2.5-pro-exp-03-25': gemini25ProExp0325,
656+
'gemini-2.5-pro-preview-03-25': gemini25ProPreview0325,
657+
'gemini-2.5-pro-preview-tts': gemini25ProPreviewTts,
658+
'gemini-2.5-flash-preview-04-17': gemini25FlashPreview0417,
659+
'gemini-2.5-flash-preview-tts': gemini25FlashPreviewTts,
660+
'gemini-2.5-flash': gemini25Flash,
661+
'gemini-2.5-flash-lite': gemini25FlashLite,
662+
'gemini-2.5-pro': gemini25Pro,
663+
'gemma-3-12b-it': gemma312bit,
664+
'gemma-3-1b-it': gemma31bit,
665+
'gemma-3-27b-it': gemma327bit,
666+
'gemma-3-4b-it': gemma34bit,
667+
'gemma-3n-e4b-it': gemma3ne4bit,
668668
};
669669

670670
export const GENERIC_GEMINI_MODEL = modelRef({
@@ -1149,6 +1149,7 @@ export function defineGoogleAIModel({
11491149
}
11501150
}
11511151

1152+
// Extract the API model name for lookup and API calls
11521153
const apiModelName = name.startsWith('googleai/')
11531154
? name.substring('googleai/'.length)
11541155
: name;

js/plugins/googleai/src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
227227
Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) => {
228228
actions.push(
229229
defineGoogleAIModel({
230-
name,
230+
name: `googleai/${name}`,
231231
apiKey: options?.apiKey,
232232
apiVersion: 'v1beta',
233233
baseUrl: options?.baseUrl,
@@ -241,7 +241,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
241241
Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) => {
242242
actions.push(
243243
defineGoogleAIModel({
244-
name,
244+
name: `googleai/${name}`,
245245
apiKey: options?.apiKey,
246246
baseUrl: options?.baseUrl,
247247
debugTraces: options?.experimental_debugTraces,
@@ -250,7 +250,9 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
250250
});
251251
Object.keys(EMBEDDER_MODELS).forEach((name) => {
252252
actions.push(
253-
defineGoogleAIEmbedder(name, { apiKey: options?.apiKey })
253+
defineGoogleAIEmbedder(`googleai/${name}`, {
254+
apiKey: options?.apiKey,
255+
})
254256
);
255257
});
256258
}
@@ -278,18 +280,20 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
278280
},
279281
async resolve(actionType: ActionType, actionName: string) {
280282
if (actionType === 'embedder') {
281-
return defineGoogleAIEmbedder(actionName, { apiKey: options?.apiKey });
283+
return defineGoogleAIEmbedder(`googleai/${actionName}`, {
284+
apiKey: options?.apiKey,
285+
});
282286
} else if (actionName.startsWith('veo')) {
283287
if (actionType === 'background-model') {
284-
return defineVeoModel(actionName, options?.apiKey);
288+
return defineVeoModel(`googleai/${actionName}`, options?.apiKey);
285289
}
286290
} else if (actionType === 'model') {
287291
if (actionName.startsWith('imagen')) {
288-
return defineImagenModel(actionName, options?.apiKey);
292+
return defineImagenModel(`googleai/${actionName}`, options?.apiKey);
289293
}
290294
// Fallback dynamic Gemini model
291295
return defineGoogleAIModel({
292-
name: actionName,
296+
name: `googleai/${actionName}`,
293297
apiKey: options?.apiKey,
294298
baseUrl: options?.baseUrl,
295299
debugTraces: options?.experimental_debugTraces,

js/plugins/googleai/tests/gemini_test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ describe('plugin', () => {
619619
toolChoice: true,
620620
systemRole: true,
621621
constrained: 'no-tools',
622+
contextCache: true,
622623
});
623624

624625
const bananaRef = gemini('gemini-4.0-banana');

0 commit comments

Comments
 (0)