2025-06-13 01:25:42 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-11-18 12:01:16 -05:00
|
|
|
export const PREVIEW_GEMINI_MODEL = 'gemini-3-pro-preview';
|
2025-06-17 23:08:04 -07:00
|
|
|
export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro';
|
2025-06-19 22:54:00 -07:00
|
|
|
export const DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash';
|
2025-07-27 17:40:55 -04:00
|
|
|
export const DEFAULT_GEMINI_FLASH_LITE_MODEL = 'gemini-2.5-flash-lite';
|
2025-08-01 17:11:51 -04:00
|
|
|
|
2025-09-12 15:57:07 -04:00
|
|
|
export const DEFAULT_GEMINI_MODEL_AUTO = 'auto';
|
|
|
|
|
|
2025-11-18 12:01:16 -05:00
|
|
|
// Model aliases for user convenience.
|
|
|
|
|
export const GEMINI_MODEL_ALIAS_PRO = 'pro';
|
|
|
|
|
export const GEMINI_MODEL_ALIAS_FLASH = 'flash';
|
|
|
|
|
export const GEMINI_MODEL_ALIAS_FLASH_LITE = 'flash-lite';
|
|
|
|
|
|
2025-06-13 01:25:42 -07:00
|
|
|
export const DEFAULT_GEMINI_EMBEDDING_MODEL = 'gemini-embedding-001';
|
2025-08-29 09:20:50 -07:00
|
|
|
|
2025-11-03 13:39:06 -05:00
|
|
|
// Cap the thinking at 8192 to prevent run-away thinking loops.
|
|
|
|
|
export const DEFAULT_THINKING_MODE = 8192;
|
2025-09-11 13:38:50 -04:00
|
|
|
|
2025-11-18 12:01:16 -05:00
|
|
|
/**
|
|
|
|
|
* Resolves the requested model alias (e.g., 'auto', 'pro', 'flash', 'flash-lite')
|
|
|
|
|
* to a concrete model name, considering preview features.
|
|
|
|
|
*
|
|
|
|
|
* @param requestedModel The model alias or concrete model name requested by the user.
|
|
|
|
|
* @param previewFeaturesEnabled A boolean indicating if preview features are enabled.
|
|
|
|
|
* @returns The resolved concrete model name.
|
|
|
|
|
*/
|
|
|
|
|
export function resolveModel(
|
|
|
|
|
requestedModel: string,
|
|
|
|
|
previewFeaturesEnabled: boolean | undefined,
|
|
|
|
|
): string {
|
|
|
|
|
switch (requestedModel) {
|
|
|
|
|
case DEFAULT_GEMINI_MODEL_AUTO:
|
|
|
|
|
case GEMINI_MODEL_ALIAS_PRO: {
|
|
|
|
|
return previewFeaturesEnabled
|
|
|
|
|
? PREVIEW_GEMINI_MODEL
|
|
|
|
|
: DEFAULT_GEMINI_MODEL;
|
|
|
|
|
}
|
|
|
|
|
case GEMINI_MODEL_ALIAS_FLASH: {
|
|
|
|
|
return DEFAULT_GEMINI_FLASH_MODEL;
|
|
|
|
|
}
|
|
|
|
|
case GEMINI_MODEL_ALIAS_FLASH_LITE: {
|
|
|
|
|
return DEFAULT_GEMINI_FLASH_LITE_MODEL;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
return requestedModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 13:38:50 -04:00
|
|
|
/**
|
|
|
|
|
* Determines the effective model to use, applying fallback logic if necessary.
|
|
|
|
|
*
|
|
|
|
|
* When fallback mode is active, this function enforces the use of the standard
|
|
|
|
|
* fallback model. However, it makes an exception for "lite" models (any model
|
|
|
|
|
* with "lite" in its name), allowing them to be used to preserve cost savings.
|
|
|
|
|
* This ensures that "pro" models are always downgraded, while "lite" model
|
|
|
|
|
* requests are honored.
|
|
|
|
|
*
|
|
|
|
|
* @param isInFallbackMode Whether the application is in fallback mode.
|
|
|
|
|
* @param requestedModel The model that was originally requested.
|
2025-11-18 12:01:16 -05:00
|
|
|
* @param previewFeaturesEnabled A boolean indicating if preview features are enabled.
|
2025-09-11 13:38:50 -04:00
|
|
|
* @returns The effective model name.
|
|
|
|
|
*/
|
|
|
|
|
export function getEffectiveModel(
|
|
|
|
|
isInFallbackMode: boolean,
|
|
|
|
|
requestedModel: string,
|
2025-11-18 12:01:16 -05:00
|
|
|
previewFeaturesEnabled: boolean | undefined,
|
2025-09-11 13:38:50 -04:00
|
|
|
): string {
|
2025-11-18 12:01:16 -05:00
|
|
|
const resolvedModel = resolveModel(requestedModel, previewFeaturesEnabled);
|
|
|
|
|
|
|
|
|
|
// If we are not in fallback mode, simply use the resolved model.
|
2025-09-11 13:38:50 -04:00
|
|
|
if (!isInFallbackMode) {
|
2025-11-18 12:01:16 -05:00
|
|
|
return resolvedModel;
|
2025-09-11 13:38:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If a "lite" model is requested, honor it. This allows for variations of
|
|
|
|
|
// lite models without needing to list them all as constants.
|
2025-11-18 12:01:16 -05:00
|
|
|
if (resolvedModel.includes('lite')) {
|
|
|
|
|
return resolvedModel;
|
2025-09-11 13:38:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Default fallback for Gemini CLI.
|
|
|
|
|
return DEFAULT_GEMINI_FLASH_MODEL;
|
|
|
|
|
}
|
2025-11-18 12:01:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if the model is a Gemini 2.x model.
|
|
|
|
|
*
|
|
|
|
|
* @param model The model name to check.
|
|
|
|
|
* @returns True if the model is a Gemini 2.x model.
|
|
|
|
|
*/
|
|
|
|
|
export function isGemini2Model(model: string): boolean {
|
|
|
|
|
return /^gemini-2(\.|$)/.test(model);
|
|
|
|
|
}
|