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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -235,7 +235,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.'
)
Expand Down
126 changes: 121 additions & 5 deletions js/plugins/googleai/src/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
type JSONSchema,
} from 'genkit';
import {
GenerationCommonConfigDescriptions,
GenerationCommonConfigSchema,
getBasicUsageStats,
modelRef,
Expand Down Expand Up @@ -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.')
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions js/plugins/googleai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from './embedder.js';
import {
GeminiConfigSchema,
SUPPORTED_V15_MODELS,
SUPPORTED_GEMINI_MODELS,
defineGoogleAIModel,
gemini,
gemini10Pro,
Expand Down Expand Up @@ -108,7 +108,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,
Expand All @@ -120,7 +120,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,
Expand Down