mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Add a tsx tool sample
This commit is contained in:
24
chat-sample/package-lock.json
generated
24
chat-sample/package-lock.json
generated
@ -11,14 +11,14 @@
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.5.9",
|
||||
"@types/vscode": "^1.90.0",
|
||||
"@vscode/prompt-tsx": "^0.1.10-alpha",
|
||||
"@vscode/prompt-tsx": "^0.2.7-alpha",
|
||||
"eslint": "^7.22.0",
|
||||
"run-script-os": "^1.1.6",
|
||||
"tslint": "^6.1.3",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.90.0"
|
||||
"vscode": "^1.93.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aashutoshrathi/word-wrap": {
|
||||
@ -204,15 +204,6 @@
|
||||
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@microsoft/tiktokenizer": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/tiktokenizer/-/tiktokenizer-1.0.6.tgz",
|
||||
"integrity": "sha512-Vi12N9vsU9jP3L95Ji1ZNMZyEbA9zIhLQd3oUPufoPqQZsnH2UGV2e2PDp2auJr7HvuDejGznWzHPj0pIjgBWg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.0.tgz",
|
||||
@ -229,13 +220,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@vscode/prompt-tsx": {
|
||||
"version": "0.1.10-alpha",
|
||||
"resolved": "https://registry.npmjs.org/@vscode/prompt-tsx/-/prompt-tsx-0.1.10-alpha.tgz",
|
||||
"integrity": "sha512-iqe1XlYsmxGGle7hmMnKd4DOebjFVmQ2odgoSzCYutOzHcqMzlRPac2sNYDQLpYlvutFi0vXl+VMPg0D3uOvVA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@microsoft/tiktokenizer": "^1.0.6"
|
||||
}
|
||||
"version": "0.2.7-alpha",
|
||||
"resolved": "https://registry.npmjs.org/@vscode/prompt-tsx/-/prompt-tsx-0.2.7-alpha.tgz",
|
||||
"integrity": "sha512-E2jmCMoNbY1XYI2yiDs7WNZD6mbv5ILZxSc94DOLRY44Qw0ozNm6DLUthN+7pHVhYVjxkMLkvBBuCCF9W9isIg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.11.2",
|
||||
|
||||
@ -41,6 +41,15 @@
|
||||
"userDescription": "The number of active tabs in the editor",
|
||||
"icon": "$(files)",
|
||||
"canBeInvokedManually": true
|
||||
},
|
||||
{
|
||||
"id": "chat-sample_catVoice",
|
||||
"name": "catVoice",
|
||||
"displayName": "Cat Voice",
|
||||
"modelDescription": "Speak in a cat voice",
|
||||
"userDescription": "Speak in a cat voice",
|
||||
"icon": "$(files)",
|
||||
"canBeInvokedManually": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -57,7 +66,7 @@
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.5.9",
|
||||
"@types/vscode": "^1.90.0",
|
||||
"@vscode/prompt-tsx": "^0.1.10-alpha",
|
||||
"@vscode/prompt-tsx": "^0.2.7-alpha",
|
||||
"eslint": "^7.22.0",
|
||||
"run-script-os": "^1.1.6",
|
||||
"tslint": "^6.1.3",
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { contentType, renderElementJSON } from '@vscode/prompt-tsx';
|
||||
import * as vscode from 'vscode';
|
||||
import { CatToolPrompt } from './play';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(registerChatTool());
|
||||
@ -6,6 +8,17 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
function registerChatTool() {
|
||||
vscode.lm.registerTool('chat-sample_catVoice', {
|
||||
async invoke(parameters, token) {
|
||||
return {
|
||||
[contentType]: await renderElementJSON(CatToolPrompt, {}, parameters.tokenOptions, token),
|
||||
toString() {
|
||||
return 'Reply in the voice of a cat! Use cat analogies when appropriate.';
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
return vscode.lm.registerTool('chat-sample_tabCount', {
|
||||
async invoke(parameters, token) {
|
||||
return {
|
||||
|
||||
@ -2,6 +2,7 @@ import {
|
||||
BasePromptElementProps,
|
||||
PromptElement,
|
||||
PromptSizing,
|
||||
TextChunk,
|
||||
UserMessage
|
||||
} from '@vscode/prompt-tsx';
|
||||
|
||||
@ -23,3 +24,15 @@ export class PlayPrompt extends PromptElement<PromptProps, void> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class CatToolPrompt extends PromptElement<BasePromptElementProps, void> {
|
||||
render(state: void, sizing: PromptSizing) {
|
||||
return (
|
||||
<>
|
||||
<TextChunk>
|
||||
Reply in the voice of a cat! Use cat analogies when appropriate.
|
||||
</TextChunk>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user