diff --git a/chat-tutorial/package-lock.json b/chat-tutorial/package-lock.json index 2a5ce3be..dfe4b92f 100644 --- a/chat-tutorial/package-lock.json +++ b/chat-tutorial/package-lock.json @@ -12,7 +12,7 @@ "@stylistic/eslint-plugin": "^2.9.0", "@types/mocha": "^10.0.3", "@types/node": "18.x", - "@types/vscode": "^1.93.0", + "@types/vscode": "^1.94.0", "@vscode/test-electron": "^2.3.6", "eslint": "^9.13.0", "glob": "^10.3.10", @@ -376,9 +376,9 @@ } }, "node_modules/@types/vscode": { - "version": "1.93.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.93.0.tgz", - "integrity": "sha512-kUK6jAHSR5zY8ps42xuW89NLcBpw1kOabah7yv38J8MyiYuOHxLQBi0e7zeXbQgVefDy/mZZetqEFC+Fl5eIEQ==", + "version": "1.95.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.95.0.tgz", + "integrity": "sha512-0LBD8TEiNbet3NvWsmn59zLzOFu/txSlGxnv5yAFHCrhG9WvAnR3IvfHzMOs2aeWqgvNjq9pO99IUw8d3n+unw==", "dev": true }, "node_modules/@typescript-eslint/type-utils": { @@ -3342,9 +3342,9 @@ } }, "@types/vscode": { - "version": "1.93.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.93.0.tgz", - "integrity": "sha512-kUK6jAHSR5zY8ps42xuW89NLcBpw1kOabah7yv38J8MyiYuOHxLQBi0e7zeXbQgVefDy/mZZetqEFC+Fl5eIEQ==", + "version": "1.95.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.95.0.tgz", + "integrity": "sha512-0LBD8TEiNbet3NvWsmn59zLzOFu/txSlGxnv5yAFHCrhG9WvAnR3IvfHzMOs2aeWqgvNjq9pO99IUw8d3n+unw==", "dev": true }, "@typescript-eslint/type-utils": { diff --git a/chat-tutorial/package.json b/chat-tutorial/package.json index c0cf5ccb..0ff54092 100644 --- a/chat-tutorial/package.json +++ b/chat-tutorial/package.json @@ -42,7 +42,7 @@ "@stylistic/eslint-plugin": "^2.9.0", "@types/mocha": "^10.0.3", "@types/node": "18.x", - "@types/vscode": "^1.93.0", + "@types/vscode": "^1.94.0", "@vscode/test-electron": "^2.3.6", "eslint": "^9.13.0", "glob": "^10.3.10", diff --git a/chat-tutorial/src/extension.ts b/chat-tutorial/src/extension.ts index 5807e54b..2b3db260 100644 --- a/chat-tutorial/src/extension.ts +++ b/chat-tutorial/src/extension.ts @@ -4,9 +4,6 @@ const BASE_PROMPT = 'You are a helpful code tutor. Your job is to teach the user const EXERCISES_PROMPT = 'You are a helpful tutor. Your job is to teach the user with fun, simple exercises that they can complete in the editor. Your exercises should start simple and get more complex as the user progresses. Move one concept at a time, and do not move on to the next concept until the user provides the correct answer. Give hints in your exercises to help the user learn. If the user is stuck, you can provide the answer and explain why it is the answer. If the user asks a non-programming question, politely decline to respond.'; -// Use gpt-4o since it is fast and high quality. gpt-3.5-turbo and gpt-4 are also available. -const MODEL_SELECTOR: vscode.LanguageModelChatSelector = { vendor: 'copilot', family: 'gpt-4o' }; - export function activate(context: vscode.ExtensionContext) { // define a chat handler @@ -19,40 +16,35 @@ export function activate(context: vscode.ExtensionContext) { prompt = EXERCISES_PROMPT; } - const [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR); + // initialize the messages array with the prompt + const messages = [ + vscode.LanguageModelChatMessage.User(prompt), + ]; - // make sure the model is available - if (model) { - // initialize the messages array with the prompt - const messages = [ - vscode.LanguageModelChatMessage.User(prompt), - ]; + // get all the previous participant messages + const previousMessages = context.history.filter( + (h) => h instanceof vscode.ChatResponseTurn + ); - // get all the previous participant messages - const previousMessages = context.history.filter( - (h) => h instanceof vscode.ChatResponseTurn - ); - - // add the previous messages to the messages array - previousMessages.forEach((m) => { - let fullMessage = ''; - m.response.forEach((r) => { - const mdPart = r as vscode.ChatResponseMarkdownPart; - fullMessage += mdPart.value.value; - }); - messages.push(vscode.LanguageModelChatMessage.Assistant(fullMessage)); + // add the previous messages to the messages array + previousMessages.forEach((m) => { + let fullMessage = ''; + m.response.forEach((r) => { + const mdPart = r as vscode.ChatResponseMarkdownPart; + fullMessage += mdPart.value.value; }); + messages.push(vscode.LanguageModelChatMessage.Assistant(fullMessage)); + }); - // add in the user's message - messages.push(vscode.LanguageModelChatMessage.User(request.prompt)); + // add in the user's message + messages.push(vscode.LanguageModelChatMessage.User(request.prompt)); - // send the request - const chatResponse = await model.sendRequest(messages, {}, token); + // send the request + const chatResponse = await request.model.sendRequest(messages, {}, token); - // stream the response - for await (const fragment of chatResponse.text) { - stream.markdown(fragment); - } + // stream the response + for await (const fragment of chatResponse.text) { + stream.markdown(fragment); } return;