/
vscode.proposed.languageModels.d.ts
211 lines (181 loc) · 6.57 KB
/
vscode.proposed.languageModels.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
/**
* Represents a language model response.
*
* @see {@link LanguageModelAccess.chatRequest}
*/
export interface LanguageModelChatResponse {
/**
* An async iterable that is a stream of text chunks forming the overall response.
*
* *Note* that this stream will error when during receiving an error occurrs.
*/
stream: AsyncIterable<string>;
}
/**
* A language model message that represents a system message.
*
* System messages provide instructions to the language model that define the context in
* which user messages are interpreted.
*
* *Note* that a language model may choose to add additional system messages to the ones
* provided by extensions.
*/
export class LanguageModelChatSystemMessage {
/**
* The content of this message.
*/
content: string;
/**
* Create a new system message.
*
* @param content The content of the message.
*/
constructor(content: string);
}
/**
* A language model message that represents a user message.
*/
export class LanguageModelChatUserMessage {
/**
* The content of this message.
*/
content: string;
/**
* The optional name of a user for this message.
*/
name: string | undefined;
/**
* Create a new user message.
*
* @param content The content of the message.
* @param name The optional name of a user for the message.
*/
constructor(content: string, name?: string);
}
/**
* A language model message that represents an assistant message, usually in response to a user message
* or as a sample response/reply-pair.
*/
export class LanguageModelChatAssistantMessage {
/**
* The content of this message.
*/
content: string;
/**
* Create a new assistant message.
*
* @param content The content of the message.
*/
constructor(content: string);
}
export type LanguageModelChatMessage = LanguageModelChatSystemMessage | LanguageModelChatUserMessage | LanguageModelChatAssistantMessage;
/**
* An event describing the change in the set of available language models.
*/
export interface LanguageModelChangeEvent {
/**
* Added language models.
*/
readonly added: readonly string[];
/**
* Removed language models.
*/
readonly removed: readonly string[];
}
/**
* An error type for language model specific errors.
*
* Consumers of language models should check the code property to determine specific
* failure causes, like `if(someError.code === vscode.LanguageModelError.NotFound.name) {...}`
* for the case of referring to an unknown language model.
*/
export class LanguageModelError extends Error {
/**
* The language model does not exist.
*/
static NotFound(message?: string): LanguageModelError;
/**
* The requestor does not have permissions to use this
* language model
*/
static NoPermissions(message?: string): LanguageModelError;
/**
* A code that identifies this error.
*
* Possible values are names of errors, like {@linkcode LanguageModelError.NotFound NotFound},
* or `Unknown` for unspecified errors from the language model itself. In the latter case the
* `cause`-property will contain the actual error.
*/
readonly code: string;
}
/**
* Options for making a chat request using a language model.
*
* @see {@link lm.chatRequest}
*/
export interface LanguageModelChatRequestOptions {
/**
* A human-readable message that explains why access to a language model is needed and what feature is enabled by it.
*/
justification?: string;
/**
* Do not show the consent UI if the user has not yet granted access to the language model but fail the request instead.
*/
// TODO@API refine/define
silent?: boolean;
/**
* A set of options that control the behavior of the language model. These options are specific to the language model
* and need to be lookup in the respective documentation.
*/
modelOptions?: { [name: string]: any };
}
/**
* Namespace for language model related functionality.
*/
export namespace lm {
/**
* Make a chat request using a language model.
*
* *Note* that language model use may be subject to access restrictions and user consent. This function will return a rejected promise
* if access to the language model is not possible. Reasons for this can be:
*
* - user consent not given
* - quote limits exceeded
* - model does not exist
*
* @param languageModel A language model identifier. See {@link languageModels} for aviailable values.
* @param messages An array of message instances.
* @param options Objects that control the request.
* @param token A cancellation token which controls the request. See {@link CancellationTokenSource} for how to create one.
* @returns A thenable that resolves to a {@link LanguageModelChatResponse}. The promise will reject when making the request failed.
*/
// TODO@API refine doc
// TODO@API ExtensionContext#permission#languageModels: { languageModel: string: LanguageModelAccessInformation}
// TODO@API ✅ define specific error types?
// TODO@API ✅ NAME: sendChatRequest, fetchChatResponse, makeChatRequest, chat, chatRequest sendChatRequest
// TODO@API ✅ NAME: LanguageModelChatXYZMessage
// TODO@API ✅ errors on everything that prevents us to make the actual request
// TODO@API ✅ double auth
// TODO@API ✅ NAME: LanguageModelChatResponse, ChatResponse, ChatRequestResponse
export function sendChatRequest(languageModel: string, messages: LanguageModelChatMessage[], options: LanguageModelChatRequestOptions, token: CancellationToken): Thenable<LanguageModelChatResponse>;
/**
* The identifiers of all language models that are currently available.
*/
export const languageModels: readonly string[];
/**
* An event that is fired when the set of available language models changes.
*/
export const onDidChangeLanguageModels: Event<LanguageModelChangeEvent>;
}
// export function chatRequest2<R = void>(languageModel: string, callback: (request: LanguageModelRequest) => R): Thenable<R>;
// interface LanguageModelRequest {
// readonly quota: any;
// readonly permissions: any;
// makeRequest(messages: LanguageModelChatMessage[], options: { [name: string]: any }, token: CancellationToken): LanguageModelChatResponse;
// }
}