Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions chat-sample/src/chatUtilsSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ 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 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 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);
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;
};
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);
const chatLibParticipant = vscode.chat.createChatParticipant('chat-tools-sample.catTools', handler);
chatLibParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'cat.jpeg');
context.subscriptions.push(chatLibParticipant);
}
8 changes: 4 additions & 4 deletions chat-sample/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { registerToolUserChatParticipant } from './toolParticipant';
import { registerChatTools } from './tools';

export function activate(context: vscode.ExtensionContext) {
registerSimpleParticipant(context);
registerToolUserChatParticipant(context);
registerChatLibChatParticipant(context);
registerSimpleParticipant(context);
registerToolUserChatParticipant(context);
registerChatLibChatParticipant(context);

registerChatTools(context);
registerChatTools(context);
}

export function deactivate() { }
Loading