mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 10:10:56 -07:00
feat(core): fallback to chat-base when using unrecognized models for chat (#19016)
This commit is contained in:
@@ -729,6 +729,71 @@ describe('ModelConfigService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fallback behavior', () => {
|
||||
it('should fallback to chat-base if the requested model is completely unknown', () => {
|
||||
const config: ModelConfigServiceConfig = {
|
||||
aliases: {
|
||||
'chat-base': {
|
||||
modelConfig: {
|
||||
model: 'default-fallback-model',
|
||||
generateContentConfig: {
|
||||
temperature: 0.99,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const service = new ModelConfigService(config);
|
||||
const resolved = service.getResolvedConfig({
|
||||
model: 'my-custom-model',
|
||||
isChatModel: true,
|
||||
});
|
||||
|
||||
// It preserves the requested model name, but inherits the config from chat-base
|
||||
expect(resolved.model).toBe('my-custom-model');
|
||||
expect(resolved.generateContentConfig).toEqual({
|
||||
temperature: 0.99,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty config if requested model is unknown and chat-base is not defined', () => {
|
||||
const config: ModelConfigServiceConfig = {
|
||||
aliases: {},
|
||||
};
|
||||
const service = new ModelConfigService(config);
|
||||
const resolved = service.getResolvedConfig({
|
||||
model: 'my-custom-model',
|
||||
isChatModel: true,
|
||||
});
|
||||
|
||||
expect(resolved.model).toBe('my-custom-model');
|
||||
expect(resolved.generateContentConfig).toEqual({});
|
||||
});
|
||||
|
||||
it('should NOT fallback to chat-base if the requested model is completely unknown but isChatModel is false', () => {
|
||||
const config: ModelConfigServiceConfig = {
|
||||
aliases: {
|
||||
'chat-base': {
|
||||
modelConfig: {
|
||||
model: 'default-fallback-model',
|
||||
generateContentConfig: {
|
||||
temperature: 0.99,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const service = new ModelConfigService(config);
|
||||
const resolved = service.getResolvedConfig({
|
||||
model: 'my-custom-model',
|
||||
isChatModel: false,
|
||||
});
|
||||
|
||||
expect(resolved.model).toBe('my-custom-model');
|
||||
expect(resolved.generateContentConfig).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unrecognized models', () => {
|
||||
it('should apply overrides to unrecognized model names', () => {
|
||||
const unregisteredModelName = 'my-unregistered-model-v1';
|
||||
|
||||
@@ -26,6 +26,10 @@ export interface ModelConfigKey {
|
||||
// This allows overrides to specify different settings (e.g., higher temperature)
|
||||
// specifically for retry scenarios.
|
||||
isRetry?: boolean;
|
||||
|
||||
// Indicates whether this request originates from the primary interactive chat model.
|
||||
// Enables the default fallback configuration to `chat-base` when unknown.
|
||||
isChatModel?: boolean;
|
||||
}
|
||||
|
||||
export interface ModelConfig {
|
||||
@@ -122,6 +126,7 @@ export class ModelConfigService {
|
||||
const { aliasChain, baseModel, resolvedConfig } = this.resolveAliasChain(
|
||||
context.model,
|
||||
allAliases,
|
||||
context.isChatModel,
|
||||
);
|
||||
|
||||
const modelToLevel = this.buildModelLevelMap(aliasChain, baseModel);
|
||||
@@ -159,6 +164,7 @@ export class ModelConfigService {
|
||||
private resolveAliasChain(
|
||||
requestedModel: string,
|
||||
allAliases: Record<string, ModelConfigAlias>,
|
||||
isChatModel?: boolean,
|
||||
): {
|
||||
aliasChain: string[];
|
||||
baseModel: string | undefined;
|
||||
@@ -206,6 +212,21 @@ export class ModelConfigService {
|
||||
};
|
||||
}
|
||||
|
||||
if (isChatModel) {
|
||||
const fallbackAlias = 'chat-base';
|
||||
if (allAliases[fallbackAlias]) {
|
||||
const fallbackResolution = this.resolveAliasChain(
|
||||
fallbackAlias,
|
||||
allAliases,
|
||||
);
|
||||
return {
|
||||
aliasChain: [...fallbackResolution.aliasChain, requestedModel],
|
||||
baseModel: requestedModel,
|
||||
resolvedConfig: fallbackResolution.resolvedConfig,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
aliasChain: [requestedModel],
|
||||
baseModel: requestedModel,
|
||||
|
||||
Reference in New Issue
Block a user