Path: blob/main/extensions/copilot/src/platform/endpoint/test/node/customNesEndpoint.ts
13405 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 { TokenizerType } from '../../../../util/common/tokenizer';6import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';7import { IAuthenticationService } from '../../../authentication/common/authentication';8import { IChatMLFetcher } from '../../../chat/common/chatMLFetcher';9import { CHAT_MODEL, IConfigurationService } from '../../../configuration/common/configurationService';10import { IEnvService } from '../../../env/common/envService';11import { ILogService } from '../../../log/common/logService';12import { IFetcherService } from '../../../networking/common/fetcherService';13import { IEndpointBody } from '../../../networking/common/networking';14import { IChatWebSocketManager } from '../../../networking/node/chatWebSocketManager';15import { IExperimentationService } from '../../../telemetry/common/nullExperimentationService';16import { ITelemetryService } from '../../../telemetry/common/telemetry';17import { ITokenizerProvider } from '../../../tokenizer/node/tokenizer';18import { ICAPIClientService } from '../../common/capiClient';19import { IDomainService } from '../../common/domainService';20import { IChatModelInformation } from '../../common/endpointProvider';21import { ChatEndpoint } from '../../node/chatEndpoint';2223export class CustomNesEndpoint extends ChatEndpoint {24constructor(25@IDomainService domainService: IDomainService,26@ICAPIClientService capiClientService: ICAPIClientService,27@IFetcherService fetcherService: IFetcherService,28@IEnvService envService: IEnvService,29@ITelemetryService telemetryService: ITelemetryService,30@IAuthenticationService authService: IAuthenticationService,31@IChatMLFetcher chatMLFetcher: IChatMLFetcher,32@ITokenizerProvider tokenizerProvider: ITokenizerProvider,33@IInstantiationService instantiationService: IInstantiationService,34@IConfigurationService configurationService: IConfigurationService,35@IExperimentationService experimentationService: IExperimentationService,36@IChatWebSocketManager chatWebSocketService: IChatWebSocketManager,37@ILogService logService: ILogService38) {39const modelInfo: IChatModelInformation = {40id: CHAT_MODEL.CUSTOM_NES,41vendor: 'Custom NES',42name: 'custom-nes',43model_picker_enabled: false,44is_chat_default: false,45is_chat_fallback: false,46version: 'unknown',47capabilities: {48type: 'chat',49family: 'custom-nes',50tokenizer: TokenizerType.O200K,51limits: {52// TODO@ulugbekna: copied from CAPI's 4o-mini53max_prompt_tokens: 12285,54max_output_tokens: 4096,55},56supports: {57streaming: true,58parallel_tool_calls: false,59tool_calls: false,60vision: false,61prediction: true,62}63}64};65super(66modelInfo,67domainService,68chatMLFetcher,69tokenizerProvider,70instantiationService,71configurationService,72experimentationService,73chatWebSocketService,74logService75);76}7778override get urlOrRequestMetadata(): string {79const url = process.env.CUSTOM_NES_URL;80if (!url) {81throw new Error(`No url found for custom NES model`);82}83return url;84}8586private getSecretKey(): string {87const secretKey: string | undefined = process.env.CUSTOM_NES_TOKEN;88if (!secretKey) {89throw new Error(`No secret key found for custom NES model`);90}91return secretKey;92}9394private getAuthHeader(): string {95return 'Bearer ' + this.getSecretKey();96}9798public override getExtraHeaders(): Record<string, string> {99return {100'Authorization': this.getAuthHeader(),101'api-key': this.getSecretKey(),102};103}104105override interceptBody(body: IEndpointBody | undefined): void {106super.interceptBody(body);107if (body) {108delete body.snippy;109delete body.intent;110}111}112}113114115