Path: blob/main/extensions/copilot/src/extension/prompt/vscode-node/scenarioAutomationEndpointProviderImpl.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { ChatRequest, LanguageModelChat, lm } from 'vscode';6import { ConfigKey } from '../../../platform/configuration/common/configurationService';7import { ChatEndpointFamily } from '../../../platform/endpoint/common/endpointProvider';8import { ExtensionContributedChatEndpoint } from '../../../platform/endpoint/vscode-node/extChatEndpoint';9import { IChatEndpoint } from '../../../platform/networking/common/networking';10import { ProductionEndpointProvider } from './endpointProviderImpl';1112export class ScenarioAutomationEndpointProviderImpl extends ProductionEndpointProvider {13override async getChatEndpoint(requestOrFamilyOrModel: LanguageModelChat | ChatRequest | ChatEndpointFamily): Promise<IChatEndpoint> {14const isProxyingCAPI = !!this._configService.getConfig(ConfigKey.Shared.DebugOverrideCAPIUrl) || !!this._configService.getConfig(ConfigKey.Shared.DebugOverrideProxyUrl);15if (this._authService.copilotToken?.isNoAuthUser && !isProxyingCAPI) {16// When using no auth in scenario automation, we want to force using a custom model / non-copilot for all requests17const getFirstNonCopilotModel = async () => {18const allModels = await lm.selectChatModels();19const firstNonCopilotModel = allModels.find(m => m.vendor !== 'copilot');20if (firstNonCopilotModel) {21this._logService.trace(`Using custom contributed chat model`);22return this._instantiationService.createInstance(ExtensionContributedChatEndpoint, firstNonCopilotModel);23} else {24throw new Error('No custom contributed chat models found.');25}26};2728// Check if we have a hard-coded family which indicates a copilot model29if (typeof requestOrFamilyOrModel === 'string') {30return getFirstNonCopilotModel();31}3233// Check if a copilot model was explicitly requested in the picker34const model = 'model' in requestOrFamilyOrModel ? requestOrFamilyOrModel.model : requestOrFamilyOrModel;35if (model.vendor === 'copilot') {36return getFirstNonCopilotModel();37}38}3940try {41return await super.getChatEndpoint(requestOrFamilyOrModel);42} catch (error) {43// In scenario automation, some model families (e.g. copilot-fast → gpt-4o-mini) may44// not be available via the capi proxy. Fall back to copilot-base.45if (typeof requestOrFamilyOrModel === 'string') {46this._logService.trace(`ScenarioAutomation: failed to resolve model family '${requestOrFamilyOrModel}', falling back to copilot-base`);47return super.getChatEndpoint('copilot-base');48}49throw error;50}51}52}5354