Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/vscode-node/scenarioAutomationEndpointProviderImpl.ts
13399 views
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
import { ChatRequest, LanguageModelChat, lm } from 'vscode';
7
import { ConfigKey } from '../../../platform/configuration/common/configurationService';
8
import { ChatEndpointFamily } from '../../../platform/endpoint/common/endpointProvider';
9
import { ExtensionContributedChatEndpoint } from '../../../platform/endpoint/vscode-node/extChatEndpoint';
10
import { IChatEndpoint } from '../../../platform/networking/common/networking';
11
import { ProductionEndpointProvider } from './endpointProviderImpl';
12
13
export class ScenarioAutomationEndpointProviderImpl extends ProductionEndpointProvider {
14
override async getChatEndpoint(requestOrFamilyOrModel: LanguageModelChat | ChatRequest | ChatEndpointFamily): Promise<IChatEndpoint> {
15
const isProxyingCAPI = !!this._configService.getConfig(ConfigKey.Shared.DebugOverrideCAPIUrl) || !!this._configService.getConfig(ConfigKey.Shared.DebugOverrideProxyUrl);
16
if (this._authService.copilotToken?.isNoAuthUser && !isProxyingCAPI) {
17
// When using no auth in scenario automation, we want to force using a custom model / non-copilot for all requests
18
const getFirstNonCopilotModel = async () => {
19
const allModels = await lm.selectChatModels();
20
const firstNonCopilotModel = allModels.find(m => m.vendor !== 'copilot');
21
if (firstNonCopilotModel) {
22
this._logService.trace(`Using custom contributed chat model`);
23
return this._instantiationService.createInstance(ExtensionContributedChatEndpoint, firstNonCopilotModel);
24
} else {
25
throw new Error('No custom contributed chat models found.');
26
}
27
};
28
29
// Check if we have a hard-coded family which indicates a copilot model
30
if (typeof requestOrFamilyOrModel === 'string') {
31
return getFirstNonCopilotModel();
32
}
33
34
// Check if a copilot model was explicitly requested in the picker
35
const model = 'model' in requestOrFamilyOrModel ? requestOrFamilyOrModel.model : requestOrFamilyOrModel;
36
if (model.vendor === 'copilot') {
37
return getFirstNonCopilotModel();
38
}
39
}
40
41
try {
42
return await super.getChatEndpoint(requestOrFamilyOrModel);
43
} catch (error) {
44
// In scenario automation, some model families (e.g. copilot-fast → gpt-4o-mini) may
45
// not be available via the capi proxy. Fall back to copilot-base.
46
if (typeof requestOrFamilyOrModel === 'string') {
47
this._logService.trace(`ScenarioAutomation: failed to resolve model family '${requestOrFamilyOrModel}', falling back to copilot-base`);
48
return super.getChatEndpoint('copilot-base');
49
}
50
throw error;
51
}
52
}
53
}
54