Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/extension/conversation/vscode-node/languageModelAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AutoChatEndpoint } from '../../../platform/endpoint/common/autoChatEndp
import { IAutomodeService } from '../../../platform/endpoint/common/automodeService';
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
import { CustomDataPartMimeTypes } from '../../../platform/endpoint/common/endpointTypes';
import { ModelAliasRegistry } from '../../../platform/endpoint/common/modelAliasRegistry';
import { encodeStatefulMarker } from '../../../platform/endpoint/common/statefulMarkerContainer';
import { IEnvService, isScenarioAutomation } from '../../../platform/env/common/envService';
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext';
Expand Down Expand Up @@ -201,6 +202,17 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
};

models.push(model);

// Register aliases for this model
const aliases = ModelAliasRegistry.getAliases(model.id);
for (const alias of aliases) {
models.push({
...model,
id: alias,
family: alias,
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting family: alias on line 212 may introduce confusion since the alias (e.g., 'copilot-fast') would be used as the family instead of the resolved model's actual family (e.g., 'gpt-4o-mini'). Consider whether the family should remain consistent with the original model's family to maintain proper categorization.

Suggested change
family: alias,
family: model.family,

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lramos15 If our internal getChatEndpoint took id instead of family, which it effectively does, I'd follow this suggestion as you also brought it up.

isUserSelectable: false,
});
}
}

this._currentModels = models;
Expand All @@ -215,7 +227,7 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
progress: vscode.Progress<vscode.LanguageModelResponsePart2>,
token: vscode.CancellationToken
): Promise<any> {
const endpoint = this._chatEndpoints.find(e => e.model === model.id);
const endpoint = this._chatEndpoints.find(e => e.model === ModelAliasRegistry.resolveAlias(model.id));
if (!endpoint) {
throw new Error(`Endpoint not found for model ${model.id}`);
}
Expand All @@ -231,7 +243,7 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
text: string | vscode.LanguageModelChatMessage | vscode.LanguageModelChatMessage2,
token: vscode.CancellationToken
): Promise<number> {
const endpoint = this._chatEndpoints.find(e => e.model === model.id);
const endpoint = this._chatEndpoints.find(e => e.model === ModelAliasRegistry.resolveAlias(model.id));
if (!endpoint) {
throw new Error(`Endpoint not found for model ${model.id}`);
}
Expand Down
50 changes: 50 additions & 0 deletions src/platform/endpoint/common/modelAliasRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export class ModelAliasRegistry {
private readonly _aliasToModelId = new Map<string, string>();
private readonly _modelIdToAliases = new Map<string, string[]>();
private static readonly _instance = new ModelAliasRegistry();

private constructor() { }

private static _updateAliasesForModelId(modelId: string): void {
const aliases: string[] = [];
for (const [alias, mappedModelId] of this._instance._aliasToModelId.entries()) {
if (mappedModelId === modelId) {
aliases.push(alias);
}
}

if (aliases.length > 0) {
this._instance._modelIdToAliases.set(modelId, aliases);
} else {
this._instance._modelIdToAliases.delete(modelId);
}
}

static registerAlias(alias: string, modelId: string): void {
this._instance._aliasToModelId.set(alias, modelId);
this._updateAliasesForModelId(modelId);
}

static deregisterAlias(alias: string): void {
const modelId = this._instance._aliasToModelId.get(alias);
this._instance._aliasToModelId.delete(alias);
if (modelId) {
this._updateAliasesForModelId(modelId);
}
}

static resolveAlias(alias: string): string {
return this._instance._aliasToModelId.get(alias) ?? alias;
}

static getAliases(modelId: string): string[] {
return this._instance._modelIdToAliases.get(modelId) ?? [];
}
}

ModelAliasRegistry.registerAlias('copilot-fast', 'gpt-4o-mini');
5 changes: 3 additions & 2 deletions src/platform/endpoint/node/modelMetadataFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IExperimentationService } from '../../telemetry/common/nullExperimentat
import { ITelemetryService } from '../../telemetry/common/telemetry';
import { ICAPIClientService } from '../common/capiClient';
import { ChatEndpointFamily, IChatModelInformation, ICompletionModelInformation, IEmbeddingModelInformation, IModelAPIResponse, isChatModelInformation, isCompletionModelInformation, isEmbeddingModelInformation } from '../common/endpointProvider';
import { ModelAliasRegistry } from '../common/modelAliasRegistry';
import { getMaxPromptTokens } from './chatEndpoint';

export interface IModelMetadataFetcher {
Expand Down Expand Up @@ -159,10 +160,10 @@ export class ModelMetadataFetcher extends Disposable implements IModelMetadataFe
public async getChatModelFromFamily(family: ChatEndpointFamily): Promise<IChatModelInformation> {
await this._taskSingler.getOrCreate(ModelMetadataFetcher.ALL_MODEL_KEY, this._fetchModels.bind(this));
let resolvedModel: IModelAPIResponse | undefined;
family = ModelAliasRegistry.resolveAlias(family) as ChatEndpointFamily;

if (family === 'gpt-4.1') {
resolvedModel = this._familyMap.get('gpt-4.1')?.[0] ?? this._familyMap.get('gpt-4o')?.[0];
} else if (family === 'copilot-fast') {
resolvedModel = this._familyMap.get('gpt-4o-mini')?.[0];
} else if (family === 'copilot-base') {
resolvedModel = this._copilotBaseModel;
} else {
Expand Down
Loading