feat(core): fallback to chat-base when using unrecognized models for chat (#19016)

This commit is contained in:
Sandy Tao
2026-02-13 11:00:08 -08:00
committed by GitHub
parent 9c285eaf15
commit e844a57bfc
4 changed files with 100 additions and 11 deletions

View File

@@ -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';