@@ -59,7 +59,7 @@ import {
5959 Tool ,
6060 ToolConfig ,
6161} from './types' ;
62- import { calculateApiKey , checkApiKey , modelName } from './utils' ;
62+ import { calculateApiKey , checkApiKey , checkModelName } from './utils' ;
6363
6464/**
6565 * See https://ai.google.dev/gemini-api/docs/safety-settings#safety-filters.
@@ -298,14 +298,28 @@ const GENERIC_GEMMA_MODEL = commonRef(
298298 GemmaConfigSchema
299299) ;
300300
301- const KNOWN_MODELS = {
301+ const KNOWN_GEMINI_MODELS = {
302+ 'gemini-2.5-pro' : commonRef ( 'gemini-2.5-pro' ) ,
303+ 'gemini-2.5-flash' : commonRef ( 'gemini-2.5-flash' ) ,
304+ 'gemini-2.5-flash-lite-preview-06-17' : commonRef (
305+ 'gemini-2.5-flash-lite-preview-06-17'
306+ ) ,
302307 'gemini-2.0-flash' : commonRef ( 'gemini-2.0-flash' ) ,
308+ 'gemini-2.0-flash-preview-image-generation' : commonRef (
309+ 'gemini-2.0-flash-preview-image-generation'
310+ ) ,
303311 'gemini-2.0-flash-lite' : commonRef ( 'gemini-2.0-flash-lite' ) ,
304- 'gemini-2.0-pro-exp-02-05' : commonRef ( 'gemini-2.0-pro-exp-02-05' ) ,
305- 'gemini-2.0-flash-exp' : commonRef ( 'gemini-2.0-flash-exp' ) ,
306- 'gemini-2.5-pro-exp-03-25' : commonRef ( 'gemini-2.5-pro-exp-03-25' ) ,
307- 'gemini-2.5-pro-preview-03-25' : commonRef ( 'gemini-2.5-pro-preview-03-25' ) ,
308- 'gemini-2.5-flash-preview-04-17' : commonRef ( 'gemini-2.5-flash-preview-04-17' ) ,
312+ 'gemini-1.5-flash' : commonRef ( 'gemini-1.5-flash' ) ,
313+ 'gemini-1.5-flash-8b' : commonRef ( 'gemini-1.5-flash-8b' ) ,
314+ 'gemini-1.5-pro' : commonRef ( 'gemini-1.5-pro' ) ,
315+ } ;
316+ export type KnownGeminiModels = keyof typeof KNOWN_GEMINI_MODELS ;
317+ export type GeminiModelName = `gemini-${string } `;
318+ export function isGeminiModelName ( value : string ) : value is GeminiModelName {
319+ return value . startsWith ( 'gemini-' ) && ! value . endsWith ( '-tts' ) ;
320+ }
321+
322+ const KNOWN_TTS_MODELS = {
309323 'gemini-2.5-flash-preview-tts' : commonRef (
310324 'gemini-2.5-flash-preview-tts' ,
311325 { ...GENERIC_TTS_MODEL . info } ,
@@ -316,36 +330,37 @@ const KNOWN_MODELS = {
316330 { ...GENERIC_TTS_MODEL . info } ,
317331 GeminiTtsConfigSchema
318332 ) ,
333+ } ;
334+ export type KnownTtsModels = keyof typeof KNOWN_TTS_MODELS ;
335+ export type TTSModelName = `gemini-${string } -tts`;
336+ export function isTTSModelName ( value : string ) : value is TTSModelName {
337+ return value . startsWith ( 'gemini-' ) && value . endsWith ( '-tts' ) ;
338+ }
339+
340+ const KNOWN_GEMMA_MODELS = {
319341 'gemma-3-12b-it' : commonRef ( 'gemma-3-12b-it' , undefined , GemmaConfigSchema ) ,
320342 'gemma-3-1b-it' : commonRef ( 'gemma-3-1b-it' , undefined , GemmaConfigSchema ) ,
321343 'gemma-3-27b-it' : commonRef ( 'gemma-3-27b-it' , undefined , GemmaConfigSchema ) ,
322344 'gemma-3-4b-it' : commonRef ( 'gemma-3-4b-it' , undefined , GemmaConfigSchema ) ,
323345 'gemma-3n-e4b-it' : commonRef ( 'gemma-3n-e4b-it' , undefined , GemmaConfigSchema ) ,
324346} as const ;
325- export type KnownModels = keyof typeof KNOWN_MODELS ; // For autocomplete
326-
327- // For conditional types in index.ts model()
328- export type TTSModelName = `gemini-${string } -tts`;
329- export function isTTSModelName ( value : string ) : value is TTSModelName {
330- return value . startsWith ( 'gemini-' ) && value . endsWith ( '-tts' ) ;
331- }
332-
347+ export type KnownGemmaModels = keyof typeof KNOWN_GEMMA_MODELS ;
333348export type GemmaModelName = `gemma-${string } `;
334349export function isGemmaModelName ( value : string ) : value is GemmaModelName {
335350 return value . startsWith ( 'gemma-' ) ;
336351}
337352
353+ const KNOWN_MODELS = {
354+ ...KNOWN_GEMINI_MODELS ,
355+ ...KNOWN_TTS_MODELS ,
356+ ...KNOWN_GEMMA_MODELS ,
357+ } ;
358+
338359export function model (
339360 version : string ,
340361 config : GeminiConfig | GeminiTtsConfig = { }
341362) : ModelReference < ConfigSchemaType > {
342- const name = modelName ( version ) ;
343- if ( ! name ) {
344- throw new GenkitError ( {
345- status : 'INVALID_ARGUMENT' ,
346- message : 'Not able to create modelReference for empty model version' ,
347- } ) ;
348- }
363+ const name = checkModelName ( version ) ;
349364
350365 if ( isTTSModelName ( name ) ) {
351366 return modelRef ( {
@@ -411,6 +426,10 @@ export function defineModel(
411426) : ModelAction {
412427 checkApiKey ( pluginOptions ?. apiKey ) ;
413428 const ref = model ( name ) ;
429+ const clientOptions : ClientOptions = {
430+ apiVersion : pluginOptions ?. apiVersion ,
431+ baseUrl : pluginOptions ?. baseUrl ,
432+ } ;
414433
415434 const middleware : ModelMiddleware [ ] = [ ] ;
416435 if ( ref . info ?. supports ?. media ) {
@@ -447,11 +466,6 @@ export function defineModel(
447466 use : middleware ,
448467 } ,
449468 async ( request , sendChunk ) => {
450- const clientOptions : ClientOptions = {
451- apiVersion : pluginOptions ?. apiVersion ,
452- baseUrl : pluginOptions ?. baseUrl ,
453- } ;
454-
455469 // Make a copy so that modifying the request will not produce side-effects
456470 const messages = [ ...request . messages ] ;
457471 if ( messages . length === 0 ) throw new Error ( 'No messages provided.' ) ;
0 commit comments