Skip to content

Commit 60ff661

Browse files
authored
feat(core): Add support for custom aliases for model configs. (#13546)
1 parent 0bf775f commit 60ff661

File tree

5 files changed

+151
-2
lines changed

5 files changed

+151
-2
lines changed

docs/get-started/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ their corresponding top-level category object in your `settings.json` file.
494494
}
495495
```
496496

497+
- **`modelConfigs.customAliases`** (object):
498+
- **Description:** Custom named presets for model configs. These are merged
499+
with (and override) the built-in aliases.
500+
- **Default:** `{}`
501+
497502
- **`modelConfigs.overrides`** (array):
498503
- **Description:** Apply specific configuration overrides based on matches,
499504
with a primary key of model (or alias). The most specific match will be

packages/cli/src/config/settingsSchema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,16 @@ const SETTINGS_SCHEMA = {
729729
'Named presets for model configs. Can be used in place of a model name and can inherit from other aliases using an `extends` property.',
730730
showInDialog: false,
731731
},
732+
customAliases: {
733+
type: 'object',
734+
label: 'Custom Model Config Aliases',
735+
category: 'Model',
736+
requiresRestart: false,
737+
default: {},
738+
description:
739+
'Custom named presets for model configs. These are merged with (and override) the built-in aliases.',
740+
showInDialog: false,
741+
},
732742
overrides: {
733743
type: 'array',
734744
label: 'Model Config Overrides',

packages/core/src/services/modelConfigService.test.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,125 @@ describe('ModelConfigService', () => {
576576
});
577577
});
578578
});
579+
580+
describe('custom aliases', () => {
581+
it('should resolve a custom alias', () => {
582+
const config: ModelConfigServiceConfig = {
583+
aliases: {},
584+
customAliases: {
585+
'my-custom-alias': {
586+
modelConfig: {
587+
model: 'gemini-custom',
588+
generateContentConfig: {
589+
temperature: 0.9,
590+
},
591+
},
592+
},
593+
},
594+
overrides: [],
595+
};
596+
const service = new ModelConfigService(config);
597+
const resolved = service.getResolvedConfig({ model: 'my-custom-alias' });
598+
599+
expect(resolved.model).toBe('gemini-custom');
600+
expect(resolved.generateContentConfig).toEqual({
601+
temperature: 0.9,
602+
});
603+
});
604+
605+
it('should allow custom aliases to override built-in aliases', () => {
606+
const config: ModelConfigServiceConfig = {
607+
aliases: {
608+
'standard-alias': {
609+
modelConfig: {
610+
model: 'gemini-standard',
611+
generateContentConfig: {
612+
temperature: 0.5,
613+
},
614+
},
615+
},
616+
},
617+
customAliases: {
618+
'standard-alias': {
619+
modelConfig: {
620+
model: 'gemini-custom-override',
621+
generateContentConfig: {
622+
temperature: 0.1,
623+
},
624+
},
625+
},
626+
},
627+
overrides: [],
628+
};
629+
const service = new ModelConfigService(config);
630+
const resolved = service.getResolvedConfig({ model: 'standard-alias' });
631+
632+
expect(resolved.model).toBe('gemini-custom-override');
633+
expect(resolved.generateContentConfig).toEqual({
634+
temperature: 0.1,
635+
});
636+
});
637+
});
638+
639+
describe('unrecognized models', () => {
640+
it('should apply overrides to unrecognized model names', () => {
641+
const unregisteredModelName = 'my-unregistered-model-v1';
642+
const config: ModelConfigServiceConfig = {
643+
aliases: {}, // No aliases defined
644+
overrides: [
645+
{
646+
match: { model: unregisteredModelName },
647+
modelConfig: {
648+
generateContentConfig: {
649+
temperature: 0.01,
650+
},
651+
},
652+
},
653+
],
654+
};
655+
const service = new ModelConfigService(config);
656+
657+
// Request the unregistered model directly
658+
const resolved = service.getResolvedConfig({
659+
model: unregisteredModelName,
660+
});
661+
662+
// It should preserve the model name and apply the override
663+
expect(resolved.model).toBe(unregisteredModelName);
664+
expect(resolved.generateContentConfig).toEqual({
665+
temperature: 0.01,
666+
});
667+
});
668+
669+
it('should apply scoped overrides to unrecognized model names', () => {
670+
const unregisteredModelName = 'my-unregistered-model-v1';
671+
const config: ModelConfigServiceConfig = {
672+
aliases: {},
673+
overrides: [
674+
{
675+
match: {
676+
model: unregisteredModelName,
677+
overrideScope: 'special-agent',
678+
},
679+
modelConfig: {
680+
generateContentConfig: {
681+
temperature: 0.99,
682+
},
683+
},
684+
},
685+
],
686+
};
687+
const service = new ModelConfigService(config);
688+
689+
const resolved = service.getResolvedConfig({
690+
model: unregisteredModelName,
691+
overrideScope: 'special-agent',
692+
});
693+
694+
expect(resolved.model).toBe(unregisteredModelName);
695+
expect(resolved.generateContentConfig).toEqual({
696+
temperature: 0.99,
697+
});
698+
});
699+
});
579700
});

packages/core/src/services/modelConfigService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface ModelConfigAlias {
4343

4444
export interface ModelConfigServiceConfig {
4545
aliases?: Record<string, ModelConfigAlias>;
46+
customAliases?: Record<string, ModelConfigAlias>;
4647
overrides?: ModelConfigOverride[];
4748
}
4849

@@ -104,8 +105,12 @@ export class ModelConfigService {
104105
generateContentConfig: GenerateContentConfig;
105106
} {
106107
const config = this.config || {};
107-
const { aliases = {}, overrides = [] } = config;
108-
const allAliases = { ...aliases, ...this.runtimeAliases };
108+
const { aliases = {}, customAliases = {}, overrides = [] } = config;
109+
const allAliases = {
110+
...aliases,
111+
...customAliases,
112+
...this.runtimeAliases,
113+
};
109114
let baseModel: string | undefined = context.model;
110115
let resolvedConfig: GenerateContentConfig = {};
111116

schemas/settings.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,14 @@
794794
"type": "object",
795795
"additionalProperties": true
796796
},
797+
"customAliases": {
798+
"title": "Custom Model Config Aliases",
799+
"description": "Custom named presets for model configs. These are merged with (and override) the built-in aliases.",
800+
"markdownDescription": "Custom named presets for model configs. These are merged with (and override) the built-in aliases.\n\n- Category: `Model`\n- Requires restart: `no`\n- Default: `{}`",
801+
"default": {},
802+
"type": "object",
803+
"additionalProperties": true
804+
},
797805
"overrides": {
798806
"title": "Model Config Overrides",
799807
"description": "Apply specific configuration overrides based on matches, with a primary key of model (or alias). The most specific match will be used.",

0 commit comments

Comments
 (0)