Skip to content

Commit 6a79d61

Browse files
sbattenCopilotlramos15
authored
make copilot-fast callable from api (#1697)
* make copilot-fast callable from api * Update src/platform/endpoint/common/modelAliasRegistry.ts Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Logan Ramos <[email protected]>
1 parent 7c6c373 commit 6a79d61

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

src/extension/conversation/vscode-node/languageModelAccess.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getTextPart } from '../../../platform/chat/common/globalStringUtils';
1414
import { EmbeddingType, getWellKnownEmbeddingTypeInfo, IEmbeddingsComputer } from '../../../platform/embeddings/common/embeddingsComputer';
1515
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
1616
import { CustomDataPartMimeTypes } from '../../../platform/endpoint/common/endpointTypes';
17+
import { ModelAliasRegistry } from '../../../platform/endpoint/common/modelAliasRegistry';
1718
import { encodeStatefulMarker } from '../../../platform/endpoint/common/statefulMarkerContainer';
1819
import { AutoChatEndpoint } from '../../../platform/endpoint/node/autoChatEndpoint';
1920
import { IAutomodeService } from '../../../platform/endpoint/node/automodeService';
@@ -201,6 +202,17 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
201202
};
202203

203204
models.push(model);
205+
206+
// Register aliases for this model
207+
const aliases = ModelAliasRegistry.getAliases(model.id);
208+
for (const alias of aliases) {
209+
models.push({
210+
...model,
211+
id: alias,
212+
family: alias,
213+
isUserSelectable: false,
214+
});
215+
}
204216
}
205217

206218
this._currentModels = models;
@@ -215,7 +227,7 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
215227
progress: vscode.Progress<vscode.LanguageModelResponsePart2>,
216228
token: vscode.CancellationToken
217229
): Promise<any> {
218-
const endpoint = this._chatEndpoints.find(e => e.model === model.id);
230+
const endpoint = this._chatEndpoints.find(e => e.model === ModelAliasRegistry.resolveAlias(model.id));
219231
if (!endpoint) {
220232
throw new Error(`Endpoint not found for model ${model.id}`);
221233
}
@@ -231,7 +243,7 @@ export class LanguageModelAccess extends Disposable implements IExtensionContrib
231243
text: string | vscode.LanguageModelChatMessage | vscode.LanguageModelChatMessage2,
232244
token: vscode.CancellationToken
233245
): Promise<number> {
234-
const endpoint = this._chatEndpoints.find(e => e.model === model.id);
246+
const endpoint = this._chatEndpoints.find(e => e.model === ModelAliasRegistry.resolveAlias(model.id));
235247
if (!endpoint) {
236248
throw new Error(`Endpoint not found for model ${model.id}`);
237249
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export class ModelAliasRegistry {
7+
private readonly _aliasToModelId = new Map<string, string>();
8+
private readonly _modelIdToAliases = new Map<string, string[]>();
9+
private static readonly _instance = new ModelAliasRegistry();
10+
11+
private constructor() { }
12+
13+
private static _updateAliasesForModelId(modelId: string): void {
14+
const aliases: string[] = [];
15+
for (const [alias, mappedModelId] of this._instance._aliasToModelId.entries()) {
16+
if (mappedModelId === modelId) {
17+
aliases.push(alias);
18+
}
19+
}
20+
21+
if (aliases.length > 0) {
22+
this._instance._modelIdToAliases.set(modelId, aliases);
23+
} else {
24+
this._instance._modelIdToAliases.delete(modelId);
25+
}
26+
}
27+
28+
static registerAlias(alias: string, modelId: string): void {
29+
this._instance._aliasToModelId.set(alias, modelId);
30+
this._updateAliasesForModelId(modelId);
31+
}
32+
33+
static deregisterAlias(alias: string): void {
34+
const modelId = this._instance._aliasToModelId.get(alias);
35+
this._instance._aliasToModelId.delete(alias);
36+
if (modelId) {
37+
this._updateAliasesForModelId(modelId);
38+
}
39+
}
40+
41+
static resolveAlias(alias: string): string {
42+
return this._instance._aliasToModelId.get(alias) ?? alias;
43+
}
44+
45+
static getAliases(modelId: string): string[] {
46+
return this._instance._modelIdToAliases.get(modelId) ?? [];
47+
}
48+
}
49+
50+
ModelAliasRegistry.registerAlias('copilot-fast', 'gpt-4o-mini');

src/platform/endpoint/node/modelMetadataFetcher.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { IExperimentationService } from '../../telemetry/common/nullExperimentat
2222
import { ITelemetryService } from '../../telemetry/common/telemetry';
2323
import { ICAPIClientService } from '../common/capiClient';
2424
import { ChatEndpointFamily, IChatModelInformation, ICompletionModelInformation, IEmbeddingModelInformation, IModelAPIResponse, isChatModelInformation, isCompletionModelInformation, isEmbeddingModelInformation } from '../common/endpointProvider';
25+
import { ModelAliasRegistry } from '../common/modelAliasRegistry';
2526
import { getMaxPromptTokens } from './chatEndpoint';
2627

2728
export interface IModelMetadataFetcher {
@@ -159,10 +160,10 @@ export class ModelMetadataFetcher extends Disposable implements IModelMetadataFe
159160
public async getChatModelFromFamily(family: ChatEndpointFamily): Promise<IChatModelInformation> {
160161
await this._taskSingler.getOrCreate(ModelMetadataFetcher.ALL_MODEL_KEY, this._fetchModels.bind(this));
161162
let resolvedModel: IModelAPIResponse | undefined;
163+
family = ModelAliasRegistry.resolveAlias(family) as ChatEndpointFamily;
164+
162165
if (family === 'gpt-4.1') {
163166
resolvedModel = this._familyMap.get('gpt-4.1')?.[0] ?? this._familyMap.get('gpt-4o')?.[0];
164-
} else if (family === 'copilot-fast') {
165-
resolvedModel = this._familyMap.get('gpt-4o-mini')?.[0];
166167
} else if (family === 'copilot-base') {
167168
resolvedModel = this._copilotBaseModel;
168169
} else {

0 commit comments

Comments
 (0)