From f2bddfe054f83ef7e93b262fadc03554abf3ba64 Mon Sep 17 00:00:00 2001 From: Pyush Sinha Date: Fri, 29 Aug 2025 09:20:50 -0700 Subject: [PATCH] fix: add flash lite with respect to api defaults (#4652) Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com> --- packages/core/src/config/models.ts | 3 ++ packages/core/src/core/client.test.ts | 41 ++++++++++++++++++++++++++- packages/core/src/core/client.ts | 21 ++++++++++---- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/packages/core/src/config/models.ts b/packages/core/src/config/models.ts index 175f05795d..1d2c1310a7 100644 --- a/packages/core/src/config/models.ts +++ b/packages/core/src/config/models.ts @@ -9,3 +9,6 @@ export const DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash'; export const DEFAULT_GEMINI_FLASH_LITE_MODEL = 'gemini-2.5-flash-lite'; export const DEFAULT_GEMINI_EMBEDDING_MODEL = 'gemini-embedding-001'; + +// Some thinking models do not default to dynamic thinking which is done by a value of -1 +export const DEFAULT_THINKING_MODE = -1; diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index 8f37c2dcc9..3aea7ad9f6 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -22,7 +22,12 @@ import type { Part, } from '@google/genai'; import { GoogleGenAI } from '@google/genai'; -import { findIndexAfterFraction, GeminiClient } from './client.js'; +import { + findIndexAfterFraction, + isThinkingDefault, + isThinkingSupported, + GeminiClient, +} from './client.js'; import { AuthType, type ContentGenerator, @@ -162,6 +167,40 @@ describe('findIndexAfterFraction', () => { }); }); +describe('isThinkingSupported', () => { + it('should return true for gemini-2.5', () => { + expect(isThinkingSupported('gemini-2.5')).toBe(true); + }); + + it('should return true for gemini-2.5-pro', () => { + expect(isThinkingSupported('gemini-2.5-pro')).toBe(true); + }); + + it('should return false for other models', () => { + expect(isThinkingSupported('gemini-1.5-flash')).toBe(false); + expect(isThinkingSupported('some-other-model')).toBe(false); + }); +}); + +describe('isThinkingDefault', () => { + it('should return false for gemini-2.5-flash-lite', () => { + expect(isThinkingDefault('gemini-2.5-flash-lite')).toBe(false); + }); + + it('should return true for gemini-2.5', () => { + expect(isThinkingDefault('gemini-2.5')).toBe(true); + }); + + it('should return true for gemini-2.5-pro', () => { + expect(isThinkingDefault('gemini-2.5-pro')).toBe(true); + }); + + it('should return false for other models', () => { + expect(isThinkingDefault('gemini-1.5-flash')).toBe(false); + expect(isThinkingDefault('some-other-model')).toBe(false); + }); +}); + describe('Gemini Client (client.ts)', () => { let client: GeminiClient; beforeEach(async () => { diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 7f2abd694d..c9cf597daa 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -36,7 +36,10 @@ import type { } from './contentGenerator.js'; import { AuthType, createContentGenerator } from './contentGenerator.js'; import { ProxyAgent, setGlobalDispatcher } from 'undici'; -import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js'; +import { + DEFAULT_GEMINI_FLASH_MODEL, + DEFAULT_THINKING_MODE, +} from '../config/models.js'; import { LoopDetectionService } from '../services/loopDetectionService.js'; import { ideContext } from '../ide/ideContext.js'; import { @@ -51,7 +54,13 @@ import { } from '../telemetry/types.js'; import type { IdeContext, File } from '../ide/ideContext.js'; -function isThinkingSupported(model: string) { +export function isThinkingSupported(model: string) { + if (model.startsWith('gemini-2.5')) return true; + return false; +} + +export function isThinkingDefault(model: string) { + if (model.startsWith('gemini-2.5-flash-lite')) return false; if (model.startsWith('gemini-2.5')) return true; return false; } @@ -245,14 +254,16 @@ export class GeminiClient { try { const userMemory = this.config.getUserMemory(); const systemInstruction = getCoreSystemPrompt(userMemory); - const generateContentConfigWithThinking = isThinkingSupported( - this.config.getModel(), - ) + const model = this.config.getModel(); + const generateContentConfigWithThinking = isThinkingSupported(model) ? { ...this.generateContentConfig, thinkingConfig: { thinkingBudget: -1, includeThoughts: true, + ...(!isThinkingDefault(model) + ? { thinkingBudget: DEFAULT_THINKING_MODE } + : {}), }, } : this.generateContentConfig;