mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 19:44:30 -07:00
feat(core): Migrate generateJson to resolved model configs. (#12626)
This commit is contained in:
@@ -15,11 +15,11 @@ import {
|
||||
} from '../../utils/messageInspectors.js';
|
||||
import {
|
||||
DEFAULT_GEMINI_FLASH_MODEL,
|
||||
DEFAULT_GEMINI_FLASH_LITE_MODEL,
|
||||
DEFAULT_GEMINI_MODEL,
|
||||
} from '../../config/models.js';
|
||||
import { promptIdContext } from '../../utils/promptIdContext.js';
|
||||
import type { Content } from '@google/genai';
|
||||
import type { ResolvedModelConfig } from '../../services/modelConfigService.js';
|
||||
|
||||
vi.mock('../../core/baseLlmClient.js');
|
||||
vi.mock('../../utils/promptIdContext.js');
|
||||
@@ -29,6 +29,7 @@ describe('ClassifierStrategy', () => {
|
||||
let mockContext: RoutingContext;
|
||||
let mockConfig: Config;
|
||||
let mockBaseLlmClient: BaseLlmClient;
|
||||
let mockResolvedConfig: ResolvedModelConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -39,7 +40,15 @@ describe('ClassifierStrategy', () => {
|
||||
request: [{ text: 'simple task' }],
|
||||
signal: new AbortController().signal,
|
||||
};
|
||||
mockConfig = {} as Config;
|
||||
mockResolvedConfig = {
|
||||
model: 'classifier',
|
||||
generateContentConfig: {},
|
||||
} as unknown as ResolvedModelConfig;
|
||||
mockConfig = {
|
||||
modelConfigService: {
|
||||
getResolvedConfig: vi.fn().mockReturnValue(mockResolvedConfig),
|
||||
},
|
||||
} as unknown as Config;
|
||||
mockBaseLlmClient = {
|
||||
generateJson: vi.fn(),
|
||||
} as unknown as BaseLlmClient;
|
||||
@@ -60,14 +69,7 @@ describe('ClassifierStrategy', () => {
|
||||
|
||||
expect(mockBaseLlmClient.generateJson).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
model: DEFAULT_GEMINI_FLASH_LITE_MODEL,
|
||||
config: expect.objectContaining({
|
||||
temperature: 0,
|
||||
maxOutputTokens: 1024,
|
||||
thinkingConfig: {
|
||||
thinkingBudget: 512,
|
||||
},
|
||||
}),
|
||||
modelConfigKey: { model: mockResolvedConfig.model },
|
||||
promptId: 'test-prompt-id',
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -14,14 +14,9 @@ import type {
|
||||
} from '../routingStrategy.js';
|
||||
import {
|
||||
DEFAULT_GEMINI_FLASH_MODEL,
|
||||
DEFAULT_GEMINI_FLASH_LITE_MODEL,
|
||||
DEFAULT_GEMINI_MODEL,
|
||||
} from '../../config/models.js';
|
||||
import {
|
||||
type GenerateContentConfig,
|
||||
createUserContent,
|
||||
Type,
|
||||
} from '@google/genai';
|
||||
import { createUserContent, Type } from '@google/genai';
|
||||
import type { Config } from '../../config/config.js';
|
||||
import {
|
||||
isFunctionCall,
|
||||
@@ -29,14 +24,6 @@ import {
|
||||
} from '../../utils/messageInspectors.js';
|
||||
import { debugLogger } from '../../utils/debugLogger.js';
|
||||
|
||||
const CLASSIFIER_GENERATION_CONFIG: GenerateContentConfig = {
|
||||
temperature: 0,
|
||||
maxOutputTokens: 1024,
|
||||
thinkingConfig: {
|
||||
thinkingBudget: 512, // This counts towards output max, so we don't want -1.
|
||||
},
|
||||
};
|
||||
|
||||
// The number of recent history turns to provide to the router for context.
|
||||
const HISTORY_TURNS_FOR_CONTEXT = 4;
|
||||
const HISTORY_SEARCH_WINDOW = 20;
|
||||
@@ -171,11 +158,10 @@ export class ClassifierStrategy implements RoutingStrategy {
|
||||
const finalHistory = cleanHistory.slice(-HISTORY_TURNS_FOR_CONTEXT);
|
||||
|
||||
const jsonResponse = await baseLlmClient.generateJson({
|
||||
modelConfigKey: { model: 'classifier' },
|
||||
contents: [...finalHistory, createUserContent(context.request)],
|
||||
schema: RESPONSE_SCHEMA,
|
||||
model: DEFAULT_GEMINI_FLASH_LITE_MODEL,
|
||||
systemInstruction: CLASSIFIER_SYSTEM_PROMPT,
|
||||
config: CLASSIFIER_GENERATION_CONFIG,
|
||||
abortSignal: context.signal,
|
||||
promptId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user