refine language model (#206358)

* api - use `LanguageModelChat` prefix for messages and response, add todos

* update todos, tweak how `chatRequest` errors, remove `LanguageModelChatResponse#result`

* api - refine language model access

removes `requestLanguageModelAccess`,
removes `LanguageModelChatResponse#result`,
adds `LanguageModelChatRequestOptions`,
refines how errors happen when making a chat request

* use `throw` over Promise.reject

* don't error from `_getAuthAccess`, polish error messages

* rename to `sendChatRequest`
This commit is contained in:
Johannes Rieken
2024-02-27 18:14:05 +01:00
committed by GitHub
parent ef300d9945
commit 4f0e2a843f
6 changed files with 158 additions and 228 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as errors from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { combinedDisposable } from 'vs/base/common/lifecycle';
@@ -1431,10 +1431,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
// namespace: lm
const lm: typeof vscode.lm = {
requestLanguageModelAccess(id, options) {
checkProposedApiEnabled(extension, 'languageModels');
return extHostChatProvider.requestLanguageModelAccess(extension, id, options);
},
get languageModels() {
checkProposedApiEnabled(extension, 'languageModels');
return extHostChatProvider.getLanguageModelIds();
@@ -1443,19 +1439,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension, 'languageModels');
return extHostChatProvider.onDidChangeProviders(listener, thisArgs, disposables);
},
chatRequest(languageModel: string, messages: vscode.LanguageModelMessage[], optionsOrToken: { [name: string]: any } | vscode.CancellationToken, token?: vscode.CancellationToken) {
sendChatRequest(languageModel: string, messages: vscode.LanguageModelChatMessage[], options: vscode.LanguageModelChatRequestOptions, token: vscode.CancellationToken) {
checkProposedApiEnabled(extension, 'languageModels');
let options: Record<string, any>;
if (CancellationToken.isCancellationToken(optionsOrToken)) {
options = {};
token = optionsOrToken;
} else if (CancellationToken.isCancellationToken(token)) {
options = optionsOrToken;
token = token;
} else {
throw new Error('Invalid arguments');
}
return extHostChatProvider.makeChatRequest(extension, languageModel, messages, options, token);
return extHostChatProvider.sendChatRequest(extension, languageModel, messages, options, token);
}
};
@@ -1699,9 +1685,12 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
ChatResponseCommandButtonPart: extHostTypes.ChatResponseCommandButtonPart,
ChatRequestTurn: extHostTypes.ChatRequestTurn,
ChatResponseTurn: extHostTypes.ChatResponseTurn,
LanguageModelSystemMessage: extHostTypes.LanguageModelSystemMessage,
LanguageModelUserMessage: extHostTypes.LanguageModelUserMessage,
LanguageModelAssistantMessage: extHostTypes.LanguageModelAssistantMessage,
LanguageModelChatSystemMessage: extHostTypes.LanguageModelChatSystemMessage,
LanguageModelChatUserMessage: extHostTypes.LanguageModelChatUserMessage,
LanguageModelChatAssistantMessage: extHostTypes.LanguageModelChatAssistantMessage,
LanguageModelSystemMessage: extHostTypes.LanguageModelChatSystemMessage,
LanguageModelUserMessage: extHostTypes.LanguageModelChatUserMessage,
LanguageModelAssistantMessage: extHostTypes.LanguageModelChatAssistantMessage,
NewSymbolName: extHostTypes.NewSymbolName,
NewSymbolNameTag: extHostTypes.NewSymbolNameTag,
InlineEdit: extHostTypes.InlineEdit,