Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/endpoint/common/endpointProvider.ts
13401 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
7
import { RequestMetadata } from '@vscode/copilot-api';
8
import type { LanguageModelChat } from 'vscode';
9
import { createServiceIdentifier } from '../../../util/common/services';
10
import { TokenizerType } from '../../../util/common/tokenizer';
11
import { Event } from '../../../util/vs/base/common/event';
12
import type { ChatRequest } from '../../../vscodeTypes';
13
import { IChatEndpoint, IEmbeddingsEndpoint } from '../../networking/common/networking';
14
15
export type CustomModel = {
16
key_name: string;
17
owner_name: string;
18
};
19
20
export type EndpointEditToolName = 'find-replace' | 'multi-find-replace' | 'apply-patch' | 'code-rewrite';
21
22
const allEndpointEditToolNames: ReadonlySet<EndpointEditToolName> = new Set([
23
'find-replace',
24
'multi-find-replace',
25
'apply-patch',
26
'code-rewrite'
27
]);
28
29
export function isEndpointEditToolName(toolName: string): toolName is EndpointEditToolName {
30
return allEndpointEditToolNames.has(toolName as EndpointEditToolName);
31
}
32
33
export type IChatModelCapabilities = {
34
type: 'chat';
35
family: string;
36
tokenizer: TokenizerType;
37
limits?: {
38
max_prompt_tokens?: number;
39
max_output_tokens?: number;
40
max_context_window_tokens?: number;
41
vision?: {
42
max_prompt_images?: number;
43
};
44
};
45
supports: {
46
parallel_tool_calls?: boolean;
47
tool_calls?: boolean;
48
// Whether or not the model supports streaming, if not explicitly true we will try to parse the response as not streamed
49
streaming: boolean | undefined;
50
vision?: boolean;
51
prediction?: boolean;
52
thinking?: boolean;
53
adaptive_thinking?: boolean;
54
max_thinking_budget?: number;
55
min_thinking_budget?: number;
56
reasoning_effort?: string[];
57
tool_search?: boolean;
58
context_editing?: boolean;
59
};
60
};
61
62
export type IEmbeddingModelCapabilities = {
63
type: 'embeddings';
64
family: string;
65
tokenizer: TokenizerType;
66
limits?: { max_inputs?: number };
67
};
68
69
type ICompletionModelCapabilities = {
70
type: 'completion';
71
family: string;
72
tokenizer: TokenizerType;
73
};
74
75
export enum ModelSupportedEndpoint {
76
ChatCompletions = '/chat/completions',
77
Responses = '/responses',
78
WebSocketResponses = 'ws:/responses',
79
Messages = '/v1/messages'
80
}
81
82
export interface IModelTokenPrices {
83
batch_size: number;
84
cache_price: number;
85
input_price: number;
86
output_price: number;
87
}
88
89
export interface IModelBilling {
90
is_premium?: boolean;
91
multiplier?: number;
92
restricted_to?: string[];
93
token_prices?: IModelTokenPrices;
94
}
95
96
export interface IModelAPIResponse {
97
id: string;
98
vendor: string;
99
name: string;
100
model_picker_enabled: boolean;
101
preview?: boolean;
102
is_chat_default: boolean;
103
is_chat_fallback: boolean;
104
version: string;
105
warning_messages?: { code: string; message: string }[];
106
info_messages?: { code: string; message: string }[];
107
billing?: IModelBilling;
108
capabilities: IChatModelCapabilities | ICompletionModelCapabilities | IEmbeddingModelCapabilities;
109
supported_endpoints?: ModelSupportedEndpoint[];
110
custom_model?: CustomModel;
111
}
112
113
export type IChatModelInformation = IModelAPIResponse & {
114
capabilities: IChatModelCapabilities;
115
urlOrRequestMetadata?: string | RequestMetadata;
116
requestHeaders?: Readonly<Record<string, string>>;
117
zeroDataRetentionEnabled?: boolean;
118
};
119
120
export function isChatModelInformation(model: IModelAPIResponse): model is IChatModelInformation {
121
return model.capabilities.type === 'chat';
122
}
123
124
export function isEmbeddingModelInformation(model: IModelAPIResponse): model is IEmbeddingModelInformation {
125
return model.capabilities.type === 'embeddings';
126
}
127
128
export type IEmbeddingModelInformation = IModelAPIResponse & { capabilities: IEmbeddingModelCapabilities };
129
130
export type ICompletionModelInformation = IModelAPIResponse & {
131
capabilities: ICompletionModelCapabilities;
132
};
133
134
export function isCompletionModelInformation(model: IModelAPIResponse): model is ICompletionModelInformation {
135
return model.capabilities.type === 'completion';
136
}
137
138
export type ChatEndpointFamily = 'copilot-base' | 'copilot-fast';
139
export type EmbeddingsEndpointFamily = 'text3small' | 'metis';
140
141
export interface IEndpointProvider {
142
readonly _serviceBrand: undefined;
143
144
/**
145
* Fires whenever model metadata is refreshed from the server.
146
* Does not always indicate there is a change, just that the data is fresh.
147
*/
148
readonly onDidModelsRefresh: Event<void>;
149
150
/**
151
* Gets all the completion models known by the endpoint provider.
152
*/
153
getAllCompletionModels(forceRefresh?: boolean): Promise<ICompletionModelInformation[]>;
154
155
/**
156
* Gets all the chat endpoints known by the endpoint provider. Mainly used by language model access
157
*/
158
getAllChatEndpoints(): Promise<IChatEndpoint[]>;
159
160
/**
161
* Given a chat request returns the appropriate chat endpoint to serve that request
162
* @param requestOrFamily The chat request to get the endpoint for, the family you want the endpoint for, or the LanguageModelChat.
163
*/
164
getChatEndpoint(requestOrFamily: LanguageModelChat | ChatRequest | ChatEndpointFamily): Promise<IChatEndpoint>;
165
166
/**
167
* Get the CAPI embedding endpoint information
168
*/
169
getEmbeddingsEndpoint(family?: EmbeddingsEndpointFamily): Promise<IEmbeddingsEndpoint>;
170
}
171
172
export const IEndpointProvider = createServiceIdentifier<IEndpointProvider>('IEndpointProvider');
173
174