diff --git a/chat-sample/src/extension.ts b/chat-sample/src/extension.ts index 600dcf03..da10a829 100644 --- a/chat-sample/src/extension.ts +++ b/chat-sample/src/extension.ts @@ -17,12 +17,12 @@ export function activate(context: vscode.ExtensionContext) { return {}; } - stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.id).join(', ')}\n\n`); + stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.name).join(', ')}\n\n`); const options: vscode.LanguageModelChatRequestOptions = { tools: vscode.lm.tools.map((tool): vscode.LanguageModelChatFunction => { return { - name: tool.id.replace(/\./g, '_'), + name: tool.name.replace(/\./g, '_'), description: tool.description, parametersSchema: tool.parametersSchema ?? {} } @@ -44,14 +44,14 @@ export function activate(context: vscode.ExtensionContext) { if (part instanceof vscode.LanguageModelChatResponseTextPart) { stream.markdown(part.value) } else if (part instanceof vscode.LanguageModelChatResponseFunctionUsePart) { - const tool = vscode.lm.tools.find(tool => tool.id.replace(/\./g, '_') === part.name); + const tool = vscode.lm.tools.find(tool => tool.name.replace(/\./g, '_') === part.name); if (!tool) { // BAD tool choice? continue; } - const resultPromise = vscode.lm.invokeTool(tool.id, JSON.parse(part.parameters), token); - stream.progress(`FUNCTION_CALL: ${tool.id} with \`${part.parameters}\``, async (progress) => { + const resultPromise = vscode.lm.invokeTool(tool.name, JSON.parse(part.parameters), token); + stream.progress(`FUNCTION_CALL: ${tool.name} with \`${part.parameters}\``, async (progress) => { await resultPromise; }); @@ -59,13 +59,13 @@ export function activate(context: vscode.ExtensionContext) { // NOTE that the result of calling a function is a special content type of a USER-message let message = vscode.LanguageModelChatMessage.User(''); - message.content2 = new vscode.LanguageModelChatMessageFunctionResultPart(tool.id, result) + message.content2 = new vscode.LanguageModelChatMessageFunctionResultPart(tool.name, result) messages.push(message) // IMPORTANT // IMPORTANT working around CAPI always wanting to end with a `User`-message // IMPORTANT - messages.push(vscode.LanguageModelChatMessage.User(`Above is the result of calling the function ${tool.id}. The user cannot see this result, so you should explain it to the user if referencing it in your answer.`)) + messages.push(vscode.LanguageModelChatMessage.User(`Above is the result of calling the function ${tool.name}. The user cannot see this result, so you should explain it to the user if referencing it in your answer.`)) didReceiveFunctionUse = true; } } diff --git a/chat-sample/vscode.proposed.chatTools.d.ts b/chat-sample/vscode.proposed.chatTools.d.ts deleted file mode 100644 index 97740f66..00000000 --- a/chat-sample/vscode.proposed.chatTools.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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' { - - export namespace lm { - /** - * Register a LanguageModelTool. The tool must also be registered in the package.json `languageModelTools` contribution point. - */ - export function registerTool(toolId: string, tool: LanguageModelTool): Disposable; - - /** - * A list of all available tools. - */ - export const tools: ReadonlyArray; - - /** - * Invoke a tool with the given parameters. - */ - export function invokeTool(toolId: string, parameters: Object, token: CancellationToken): Thenable; - } - - export interface LanguageModelToolDescription { - id: string; - description: string; - parametersSchema?: JSONSchema; - displayName?: string; - } - - export interface LanguageModelTool { - invoke(parameters: any, token: CancellationToken): Thenable; - } -} diff --git a/chat-sample/vscode.proposed.lmTools.d.ts b/chat-sample/vscode.proposed.lmTools.d.ts index 6aa0ac3a..facbeb20 100644 --- a/chat-sample/vscode.proposed.lmTools.d.ts +++ b/chat-sample/vscode.proposed.lmTools.d.ts @@ -3,6 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +// version: 2 +// https://github.com/microsoft/vscode/issues/213274 + declare module 'vscode' { // TODO@API capabilities @@ -13,7 +16,7 @@ declare module 'vscode' { export interface LanguageModelChatFunction { name: string; description: string; - parametersSchema: JSONSchema; + parametersSchema?: JSONSchema; } // API -> LM: add tools as request option @@ -55,4 +58,34 @@ declare module 'vscode' { export interface LanguageModelChatMessage { content2: string | LanguageModelChatMessageFunctionResultPart; } + + // Tool registration/invoking between extensions + + export namespace lm { + /** + * Register a LanguageModelTool. The tool must also be registered in the package.json `languageModelTools` contribution point. + */ + export function registerTool(name: string, tool: LanguageModelTool): Disposable; + + /** + * A list of all available tools. + */ + export const tools: ReadonlyArray; + + /** + * Invoke a tool with the given parameters. + */ + export function invokeTool(name: string, parameters: Object, token: CancellationToken): Thenable; + } + + // Is the same as LanguageModelChatFunction now, but could have more details in the future + export interface LanguageModelToolDescription { + name: string; + description: string; + parametersSchema?: JSONSchema; + } + + export interface LanguageModelTool { + invoke(parameters: any, token: CancellationToken): Thenable; + } }