Skip to content

fix(js): Limits on GoogleAI Gemini model config #3089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/ai/src/model.ts
Original file line number Diff line number Diff line change
@@ -240,7 +240,7 @@ export const GenerationCommonConfigSchema = z
.optional(),
stopSequences: z
.array(z.string())
.length(5)
.max(5)
.describe(
'Set of character sequences (up to 5) that will stop output generation.'
)
126 changes: 121 additions & 5 deletions js/plugins/googleai/src/gemini.ts
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ import {
type JSONSchema,
} from 'genkit';
import {
GenerationCommonConfigDescriptions,
GenerationCommonConfigSchema,
getBasicUsageStats,
modelRef,
@@ -140,6 +141,23 @@ const VoiceConfigSchema = z
.passthrough();

export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
temperature: z
.number()
.min(0)
.max(2)
.describe(
GenerationCommonConfigDescriptions.temperature +
' The default value is 1.0.'
)
.optional(),
topP: z
.number()
.min(0)
.max(1)
.describe(
GenerationCommonConfigDescriptions.topP + ' The default value is 0.95.'
)
.optional(),
apiKey: z
.string()
.describe('Overrides the plugin-configured API key, if specified.')
@@ -192,6 +210,18 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
}).passthrough();
export type GeminiConfig = z.infer<typeof GeminiConfigSchema>;

export const GeminiGemmaConfigSchema = GeminiConfigSchema.extend({
temperature: z
.number()
.min(0.0)
.max(1.0)
.describe(
GenerationCommonConfigDescriptions.temperature +
' The default value is 1.0.'
)
.optional(),
}).passthrough();

export const GeminiTtsConfigSchema = GeminiConfigSchema.extend({
speechConfig: z
.object({
@@ -452,7 +482,92 @@ export const gemini25ProPreviewTts = modelRef({
configSchema: GeminiTtsConfigSchema,
});

export const SUPPORTED_V15_MODELS = {
export const gemma312bit = modelRef({
name: 'googleai/gemma-3-12b-it',
info: {
label: 'Google AI - Gemma 3 12B',
versions: [],
supports: {
multiturn: true,
media: true,
tools: true,
toolChoice: true,
systemRole: true,
constrained: 'no-tools',
},
},
configSchema: GeminiGemmaConfigSchema,
});

export const gemma31bit = modelRef({
name: 'googleai/gemma-3-1b-it',
info: {
label: 'Google AI - Gemma 3 1B',
versions: [],
supports: {
multiturn: true,
media: true,
tools: true,
toolChoice: true,
systemRole: true,
constrained: 'no-tools',
},
},
configSchema: GeminiGemmaConfigSchema,
});

export const gemma327bit = modelRef({
name: 'googleai/gemma-3-27b-it',
info: {
label: 'Google AI - Gemma 3 27B',
versions: [],
supports: {
multiturn: true,
media: true,
tools: true,
toolChoice: true,
systemRole: true,
constrained: 'no-tools',
},
},
configSchema: GeminiGemmaConfigSchema,
});

export const gemma34bit = modelRef({
name: 'googleai/gemma-3-4b-it',
info: {
label: 'Google AI - Gemma 3 4B',
versions: [],
supports: {
multiturn: true,
media: true,
tools: true,
toolChoice: true,
systemRole: true,
constrained: 'no-tools',
},
},
configSchema: GeminiGemmaConfigSchema,
});

export const gemma3ne4bit = modelRef({
name: 'googleai/gemma-3n-e4b-it',
info: {
label: 'Google AI - Gemma 3n E4B',
versions: [],
supports: {
multiturn: true,
media: true,
tools: true,
toolChoice: true,
systemRole: true,
constrained: 'no-tools',
},
},
configSchema: GeminiGemmaConfigSchema,
});

export const SUPPORTED_GEMINI_MODELS = {
'gemini-1.5-pro': gemini15Pro,
'gemini-1.5-flash': gemini15Flash,
'gemini-1.5-flash-8b': gemini15Flash8b,
@@ -465,6 +580,11 @@ export const SUPPORTED_V15_MODELS = {
'gemini-2.5-pro-preview-tts': gemini25ProPreviewTts,
'gemini-2.5-flash-preview-04-17': gemini25FlashPreview0417,
'gemini-2.5-flash-preview-tts': gemini25FlashPreviewTts,
'gemma-3-12b-it': gemma312bit,
'gemma-3-1b-it': gemma31bit,
'gemma-3-27b-it': gemma327bit,
'gemma-3-4b-it': gemma34bit,
'gemma-3n-e4b-it': gemma3ne4bit,
};

export const GENERIC_GEMINI_MODEL = modelRef({
@@ -483,10 +603,6 @@ export const GENERIC_GEMINI_MODEL = modelRef({
},
});

export const SUPPORTED_GEMINI_MODELS = {
...SUPPORTED_V15_MODELS,
} as const;

function longestMatchingPrefix(version: string, potentialMatches: string[]) {
return potentialMatches
.filter((p) => version.startsWith(p))
5 changes: 2 additions & 3 deletions js/plugins/googleai/src/index.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@ import {
import {
GeminiConfigSchema,
SUPPORTED_GEMINI_MODELS,
SUPPORTED_V15_MODELS,
defineGoogleAIModel,
gemini,
gemini10Pro,
@@ -121,7 +120,7 @@ async function initializer(ai: Genkit, options?: PluginOptions) {
}

if (apiVersions.includes('v1beta')) {
Object.keys(SUPPORTED_V15_MODELS).forEach((name) =>
Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) =>
defineGoogleAIModel({
ai,
name,
@@ -133,7 +132,7 @@ async function initializer(ai: Genkit, options?: PluginOptions) {
);
}
if (apiVersions.includes('v1')) {
Object.keys(SUPPORTED_V15_MODELS).forEach((name) =>
Object.keys(SUPPORTED_GEMINI_MODELS).forEach((name) =>
defineGoogleAIModel({
ai,
name,