Confirmations

This commit is contained in:
Rob Lourens
2024-09-23 20:28:08 -07:00
parent ac180d2bd8
commit 22948f077b
3 changed files with 33 additions and 4 deletions

View File

@ -52,7 +52,8 @@
},
"supportedContentTypes": [
"text/plain"
]
],
"requiresConfirmation": true
},
{
"id": "chat-sample_catVoice",

View File

@ -21,6 +21,7 @@ function registerChatTool(context: vscode.ExtensionContext) {
return result;
},
provideToolInvocationMessage: async () => 'Speaking in the voice of a cat',
}));
interface ITabCountParameters {
@ -29,6 +30,7 @@ function registerChatTool(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.lm.registerTool('chat-sample_tabCount', {
async invoke(options, token) {
await new Promise(resolve => setTimeout(resolve, 5000));
const params = options.parameters as ITabCountParameters;
if (typeof params.tabGroup === 'number') {
const group = vscode.window.tabGroups.all[Math.max(params.tabGroup - 1, 0)];
@ -39,6 +41,14 @@ function registerChatTool(context: vscode.ExtensionContext) {
return { 'text/plain': `There are ${group.tabs.length} tabs open.` };
}
},
provideToolInvocationMessage: async () => 'Counting the number of tabs',
provideToolConfirmationMessages: async (options) => {
const params = options.parameters as ITabCountParameters;
return {
title: 'Count the number of open tabs',
message: new vscode.MarkdownString(`${options.participantName} will count the number of **open tabs**` + (params.tabGroup !== undefined ? ` in tab group ${params.tabGroup}` : ''))
};
}
}));
}
@ -56,7 +66,7 @@ function registerChatParticipant(context: vscode.ExtensionContext) {
});
const model = models[0];
stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.id).join(', ')}\n\n`);
// stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.id).join(', ')}\n\n`);
const allTools = vscode.lm.tools.map((tool): vscode.LanguageModelChatTool => {
return {
@ -106,7 +116,6 @@ function registerChatParticipant(context: vscode.ExtensionContext) {
throw new Error(`Got invalid tool use parameters: "${part.parameters}". (${(err as Error).message})`);
}
stream.progress(`Calling tool: ${tool.id} with ${part.parameters}`);
// TODO support prompt-tsx here
const requestedContentType = 'text/plain';
toolCalls.push({

View File

@ -166,9 +166,28 @@ declare module 'vscode' {
supportedContentTypes: string[];
}
export interface LanguageModelToolProvideConfirmationMessageOptions {
participantName: string;
parameters: any;
}
export interface LanguageModelToolConfirmationMessages {
title: string;
message: string | MarkdownString;
}
export interface LanguageModelTool {
// TODO@API should it be LanguageModelToolResult | string?
invoke(options: LanguageModelToolInvocationOptions, token: CancellationToken): ProviderResult<LanguageModelToolResult>;
/**
* This can be implemented to customize the message shown to the user when a tool requires confirmation.
*/
provideToolConfirmationMessages?(options: LanguageModelToolProvideConfirmationMessageOptions, token: CancellationToken): Thenable<LanguageModelToolConfirmationMessages>;
/**
* This message will be shown with the progress notification when the tool is invoked in a chat session.
*/
provideToolInvocationMessage?(parameters: any, token: CancellationToken): Thenable<string>;
}
export interface ChatLanguageModelToolReference {