mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
feat(core): Wire up chat code path for model configs. (#12850)
This commit is contained in:
@@ -231,4 +231,42 @@ describe('ModelConfigService Integration', () => {
|
||||
topP: 0.95, // from base
|
||||
});
|
||||
});
|
||||
|
||||
it('should correctly merge static aliases, runtime aliases, and overrides', () => {
|
||||
// Re-instantiate service for this isolated test to not pollute other tests
|
||||
const service = new ModelConfigService(complexConfig);
|
||||
|
||||
// Register a runtime alias, simulating what AgentExecutor does.
|
||||
// This alias extends a static base and provides its own settings.
|
||||
service.registerRuntimeModelConfig('agent-runtime:my-agent', {
|
||||
extends: 'creative-writer', // extends a multi-level alias
|
||||
modelConfig: {
|
||||
generateContentConfig: {
|
||||
temperature: 0.1, // Overrides parent
|
||||
maxOutputTokens: 8192, // Adds a new property
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Resolve the configuration for the runtime alias, with a matching agent scope
|
||||
const resolved = service.getResolvedConfig({
|
||||
model: 'agent-runtime:my-agent',
|
||||
overrideScope: 'core',
|
||||
});
|
||||
|
||||
// Assert the final merged configuration.
|
||||
expect(resolved.model).toBe('gemini-1.5-pro-latest'); // from 'default-text-model'
|
||||
expect(resolved.generateContentConfig).toEqual({
|
||||
// from 'core' agent override, wins over runtime alias's 0.1 and creative-writer's 0.9
|
||||
temperature: 0.5,
|
||||
// from 'base' alias
|
||||
topP: 0.95,
|
||||
// from 'creative-writer' alias
|
||||
topK: 50,
|
||||
// from runtime alias
|
||||
maxOutputTokens: 8192,
|
||||
// from 'core' agent override
|
||||
stopSequences: ['AGENT_STOP'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -550,4 +550,30 @@ describe('ModelConfigService', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runtime aliases', () => {
|
||||
it('should resolve a simple runtime-registered alias', () => {
|
||||
const config: ModelConfigServiceConfig = {
|
||||
aliases: {},
|
||||
overrides: [],
|
||||
};
|
||||
const service = new ModelConfigService(config);
|
||||
|
||||
service.registerRuntimeModelConfig('runtime-alias', {
|
||||
modelConfig: {
|
||||
model: 'gemini-runtime-model',
|
||||
generateContentConfig: {
|
||||
temperature: 0.123,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const resolved = service.getResolvedConfig({ model: 'runtime-alias' });
|
||||
|
||||
expect(resolved.model).toBe('gemini-runtime-model');
|
||||
expect(resolved.generateContentConfig).toEqual({
|
||||
temperature: 0.123,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,9 +56,15 @@ export interface _ResolvedModelConfig {
|
||||
}
|
||||
|
||||
export class ModelConfigService {
|
||||
private readonly runtimeAliases: Record<string, ModelConfigAlias> = {};
|
||||
|
||||
// TODO(12597): Process config to build a typed alias hierarchy.
|
||||
constructor(private readonly config: ModelConfigServiceConfig) {}
|
||||
|
||||
registerRuntimeModelConfig(aliasName: string, alias: ModelConfigAlias): void {
|
||||
this.runtimeAliases[aliasName] = alias;
|
||||
}
|
||||
|
||||
private resolveAlias(
|
||||
aliasName: string,
|
||||
aliases: Record<string, ModelConfigAlias>,
|
||||
@@ -99,12 +105,13 @@ export class ModelConfigService {
|
||||
} {
|
||||
const config = this.config || {};
|
||||
const { aliases = {}, overrides = [] } = config;
|
||||
const allAliases = { ...aliases, ...this.runtimeAliases };
|
||||
let baseModel: string | undefined = context.model;
|
||||
let resolvedConfig: GenerateContentConfig = {};
|
||||
|
||||
// Step 1: Alias Resolution
|
||||
if (aliases[context.model]) {
|
||||
const resolvedAlias = this.resolveAlias(context.model, aliases);
|
||||
if (allAliases[context.model]) {
|
||||
const resolvedAlias = this.resolveAlias(context.model, allAliases);
|
||||
baseModel = resolvedAlias.modelConfig.model; // This can now be undefined
|
||||
resolvedConfig = this.deepMerge(
|
||||
resolvedConfig,
|
||||
|
||||
@@ -11,7 +11,19 @@
|
||||
"topP": 0.95,
|
||||
"thinkingConfig": {
|
||||
"includeThoughts": true,
|
||||
"thinkingBudget": -1
|
||||
"thinkingBudget": 8192
|
||||
},
|
||||
"topK": 64
|
||||
}
|
||||
},
|
||||
"gemini-3-pro-preview": {
|
||||
"model": "gemini-3-pro-preview",
|
||||
"generateContentConfig": {
|
||||
"temperature": 1,
|
||||
"topP": 0.95,
|
||||
"thinkingConfig": {
|
||||
"includeThoughts": true,
|
||||
"thinkingBudget": 8192
|
||||
},
|
||||
"topK": 64
|
||||
}
|
||||
@@ -23,7 +35,7 @@
|
||||
"topP": 0.95,
|
||||
"thinkingConfig": {
|
||||
"includeThoughts": true,
|
||||
"thinkingBudget": -1
|
||||
"thinkingBudget": 8192
|
||||
},
|
||||
"topK": 64
|
||||
}
|
||||
@@ -35,7 +47,7 @@
|
||||
"topP": 0.95,
|
||||
"thinkingConfig": {
|
||||
"includeThoughts": true,
|
||||
"thinkingBudget": -1
|
||||
"thinkingBudget": 8192
|
||||
},
|
||||
"topK": 64
|
||||
}
|
||||
@@ -47,7 +59,7 @@
|
||||
"topP": 0.95,
|
||||
"thinkingConfig": {
|
||||
"includeThoughts": true,
|
||||
"thinkingBudget": -1
|
||||
"thinkingBudget": 8192
|
||||
},
|
||||
"topK": 64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user