Skip to content

Commit f2bddfe

Browse files
psinha40898galz10
andauthored
fix: add flash lite with respect to api defaults (google-gemini#4652)
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
1 parent c9e1265 commit f2bddfe

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

packages/core/src/config/models.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ export const DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash';
99
export const DEFAULT_GEMINI_FLASH_LITE_MODEL = 'gemini-2.5-flash-lite';
1010

1111
export const DEFAULT_GEMINI_EMBEDDING_MODEL = 'gemini-embedding-001';
12+
13+
// Some thinking models do not default to dynamic thinking which is done by a value of -1
14+
export const DEFAULT_THINKING_MODE = -1;

packages/core/src/core/client.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import type {
2222
Part,
2323
} from '@google/genai';
2424
import { GoogleGenAI } from '@google/genai';
25-
import { findIndexAfterFraction, GeminiClient } from './client.js';
25+
import {
26+
findIndexAfterFraction,
27+
isThinkingDefault,
28+
isThinkingSupported,
29+
GeminiClient,
30+
} from './client.js';
2631
import {
2732
AuthType,
2833
type ContentGenerator,
@@ -162,6 +167,40 @@ describe('findIndexAfterFraction', () => {
162167
});
163168
});
164169

170+
describe('isThinkingSupported', () => {
171+
it('should return true for gemini-2.5', () => {
172+
expect(isThinkingSupported('gemini-2.5')).toBe(true);
173+
});
174+
175+
it('should return true for gemini-2.5-pro', () => {
176+
expect(isThinkingSupported('gemini-2.5-pro')).toBe(true);
177+
});
178+
179+
it('should return false for other models', () => {
180+
expect(isThinkingSupported('gemini-1.5-flash')).toBe(false);
181+
expect(isThinkingSupported('some-other-model')).toBe(false);
182+
});
183+
});
184+
185+
describe('isThinkingDefault', () => {
186+
it('should return false for gemini-2.5-flash-lite', () => {
187+
expect(isThinkingDefault('gemini-2.5-flash-lite')).toBe(false);
188+
});
189+
190+
it('should return true for gemini-2.5', () => {
191+
expect(isThinkingDefault('gemini-2.5')).toBe(true);
192+
});
193+
194+
it('should return true for gemini-2.5-pro', () => {
195+
expect(isThinkingDefault('gemini-2.5-pro')).toBe(true);
196+
});
197+
198+
it('should return false for other models', () => {
199+
expect(isThinkingDefault('gemini-1.5-flash')).toBe(false);
200+
expect(isThinkingDefault('some-other-model')).toBe(false);
201+
});
202+
});
203+
165204
describe('Gemini Client (client.ts)', () => {
166205
let client: GeminiClient;
167206
beforeEach(async () => {

packages/core/src/core/client.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ import type {
3636
} from './contentGenerator.js';
3737
import { AuthType, createContentGenerator } from './contentGenerator.js';
3838
import { ProxyAgent, setGlobalDispatcher } from 'undici';
39-
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
39+
import {
40+
DEFAULT_GEMINI_FLASH_MODEL,
41+
DEFAULT_THINKING_MODE,
42+
} from '../config/models.js';
4043
import { LoopDetectionService } from '../services/loopDetectionService.js';
4144
import { ideContext } from '../ide/ideContext.js';
4245
import {
@@ -51,7 +54,13 @@ import {
5154
} from '../telemetry/types.js';
5255
import type { IdeContext, File } from '../ide/ideContext.js';
5356

54-
function isThinkingSupported(model: string) {
57+
export function isThinkingSupported(model: string) {
58+
if (model.startsWith('gemini-2.5')) return true;
59+
return false;
60+
}
61+
62+
export function isThinkingDefault(model: string) {
63+
if (model.startsWith('gemini-2.5-flash-lite')) return false;
5564
if (model.startsWith('gemini-2.5')) return true;
5665
return false;
5766
}
@@ -245,14 +254,16 @@ export class GeminiClient {
245254
try {
246255
const userMemory = this.config.getUserMemory();
247256
const systemInstruction = getCoreSystemPrompt(userMemory);
248-
const generateContentConfigWithThinking = isThinkingSupported(
249-
this.config.getModel(),
250-
)
257+
const model = this.config.getModel();
258+
const generateContentConfigWithThinking = isThinkingSupported(model)
251259
? {
252260
...this.generateContentConfig,
253261
thinkingConfig: {
254262
thinkingBudget: -1,
255263
includeThoughts: true,
264+
...(!isThinkingDefault(model)
265+
? { thinkingBudget: DEFAULT_THINKING_MODE }
266+
: {}),
256267
},
257268
}
258269
: this.generateContentConfig;

0 commit comments

Comments
 (0)