-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathchatUtilsSample.ts
35 lines (30 loc) · 1.38 KB
/
chatUtilsSample.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
import * as vscode from 'vscode';
import * as chatUtils from '@vscode/chat-extension-utils';
export function registerChatLibChatParticipant(context: vscode.ExtensionContext) {
const handler: vscode.ChatRequestHandler = async (request: vscode.ChatRequest, chatContext: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken) => {
if (request.command === 'list') {
stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.name).join(', ')}\n\n`);
return;
}
const tools = request.command === 'all' ?
vscode.lm.tools :
vscode.lm.tools.filter(tool => tool.tags.includes('chat-tools-sample'));
const libResult = chatUtils.sendChatParticipantRequest(
request,
chatContext,
{
prompt: 'You are a cat! Answer as a cat.',
responseStreamOptions: {
stream,
references: true,
responseText: true
},
tools
},
token);
return await libResult.result;
};
const chatLibParticipant = vscode.chat.createChatParticipant('chat-tools-sample.catTools', handler);
chatLibParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'cat.jpeg');
context.subscriptions.push(chatLibParticipant);
}