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