From 5ba0f312e55867633c40e41370be3d6e631e5fed Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 25 Oct 2024 12:40:23 -0700 Subject: [PATCH 1/2] Bump prompt-tsx --- package-lock.json | 9 ++++----- package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index c83e4b7..84cc70f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.9", "hasInstallScript": true, "dependencies": { - "@vscode/prompt-tsx": "^0.3.0-alpha.10", + "@vscode/prompt-tsx": "^0.3.0-alpha.12", "sanitize-filename": "^1.6.3" }, "devDependencies": { @@ -656,10 +656,9 @@ } }, "node_modules/@vscode/prompt-tsx": { - "version": "0.3.0-alpha.10", - "resolved": "https://registry.npmjs.org/@vscode/prompt-tsx/-/prompt-tsx-0.3.0-alpha.10.tgz", - "integrity": "sha512-ObWBvnHQgfTW++Fa1FJsfvNzVj6q1J9L/e5CUAYHrHpPg3b8geIlk3plHmJprT/HJmVkhC9Lqc1/moQs3m3jNA==", - "license": "MIT" + "version": "0.3.0-alpha.12", + "resolved": "https://registry.npmjs.org/@vscode/prompt-tsx/-/prompt-tsx-0.3.0-alpha.12.tgz", + "integrity": "sha512-2ANm569UBXIzjPbaDFjzRkucelhsnlnmYIPdDo+USeFq2Do0Q70gKiiRWYrQf5rPqCxrChDvgU14nsdJLUSaOQ==" }, "node_modules/@vscode/test-cli": { "version": "0.0.10", diff --git a/package.json b/package.json index 833c8b9..ae7099e 100644 --- a/package.json +++ b/package.json @@ -211,7 +211,7 @@ "unzipper": "^0.12.3" }, "dependencies": { - "@vscode/prompt-tsx": "^0.3.0-alpha.10", + "@vscode/prompt-tsx": "^0.3.0-alpha.12", "sanitize-filename": "^1.6.3" } } From 09c82076ed455f6d5f5a51a43b996fd437e48d54 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 25 Oct 2024 21:18:03 -0700 Subject: [PATCH 2/2] Adopt API changes --- src/base.tsx | 4 ++-- src/dataAgent.ts | 3 +-- src/exportCommand.ts | 4 ++-- src/test/extension.test.ts | 4 ++-- src/tools.ts | 10 +++++----- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/base.tsx b/src/base.tsx index 2a59ebd..1ea1b41 100644 --- a/src/base.tsx +++ b/src/base.tsx @@ -378,7 +378,7 @@ class ToolCalls extends PromptElement { } private async _renderOneRound(round: ToolCallRound, sizing: PromptSizing, toolInvocationToken: vscode.ChatParticipantToolToken | undefined): Promise<{ promptPiece: PromptPiece, hasError: boolean, size: number }> { - const assistantToolCalls: ToolCall[] = round.toolCalls.map(tc => ({ type: 'function', function: { name: tc.name, arguments: JSON.stringify(tc.parameters) }, id: tc.callId })); + const assistantToolCalls: ToolCall[] = round.toolCalls.map(tc => ({ type: 'function', function: { name: tc.name, arguments: JSON.stringify(tc.input) }, id: tc.callId })); const toolCallIds = round.toolCalls .map((call) => call.name) @@ -445,7 +445,7 @@ class ToolCalls extends PromptElement { const toolResult = await vscode.lm.invokeTool( tool.name, { - parameters: toolCall.parameters, + input: toolCall.input, toolInvocationToken: toolInvocationToken, tokenizationOptions: { tokenBudget: sizing.tokenBudget, diff --git a/src/dataAgent.ts b/src/dataAgent.ts index 69b3ccb..0983412 100644 --- a/src/dataAgent.ts +++ b/src/dataAgent.ts @@ -72,8 +72,7 @@ export class DataAgent implements vscode.Disposable { const allTools = vscode.lm.tools.map((tool): vscode.LanguageModelChatTool => { return { name: tool.name, - description: tool.description, - parametersSchema: tool.parametersSchema ?? {} + description: tool.description }; }); diff --git a/src/exportCommand.ts b/src/exportCommand.ts index b6ac79e..f8e1953 100644 --- a/src/exportCommand.ts +++ b/src/exportCommand.ts @@ -5,13 +5,13 @@ import * as fs from 'fs'; import { EOL } from 'os'; import { unescape } from 'querystring'; +import sanitize from 'sanitize-filename'; import { promisify } from 'util'; import { CancellationToken, ChatContext, ChatRequest, ChatResponseMarkdownPart, ChatResponseStream, ChatResponseTurn, ExtensionContext, l10n, NotebookCellData, NotebookCellKind, NotebookCellOutput, NotebookData, ThemeIcon, Uri, window, workspace } from "vscode"; import { getToolResultValue, isErrorMessageResponse, TsxToolUserMetadata } from "./base"; import { logger } from "./logger"; import { uint8ArrayToBase64 } from "./platform/common/string"; import { RunPythonTool } from "./tools"; -import sanitize from 'sanitize-filename'; const JupyterNotebookView = 'jupyter-notebook'; // enum CellOutputMimeTypes { @@ -104,7 +104,7 @@ export class JupyterNotebookExporter { return; } - const parameters = tool.parameters as { code: string; reason: string }; + const parameters = tool.input as { code: string; reason: string }; if (!parameters.code && !parameters.reason) { logger.warn(`Ignoring tool call as code & reason are empty`); return; diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 9f7c8c8..4c6fb4f 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -99,7 +99,7 @@ suite('Extension Test Suite', () => { let code = ''; if (Array.isArray(toolcall)) { for (const call of toolcall) { - code = (call.toolCalls.find(t => t.name === RunPythonTool.Id)!.parameters as any)!.code; + code = (call.toolCalls.find(t => t.name === RunPythonTool.Id)!.input as any)!.code; if (code) { const fragments = expectedCode.slice(); const found = fragments.filter(fragment => code.toLowerCase().includes(fragment.toLowerCase())); @@ -110,7 +110,7 @@ suite('Extension Test Suite', () => { } assert.fail(`Code ${expectedCode.join(', ')} not found in toolcall`); } else { - code = (toolcall.toolCalls.find(t => t.name === RunPythonTool.Id)!.parameters as any)!.code; + code = (toolcall.toolCalls.find(t => t.name === RunPythonTool.Id)!.input as any)!.code; assert.isOk(code); for (const fragment of expectedCode) { assert.include(code.toLowerCase(), fragment.toLowerCase()); diff --git a/src/tools.ts b/src/tools.ts index a20db6e..49b4e7a 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -22,7 +22,7 @@ export class FindFilesTool implements vscode.LanguageModelTool, token: vscode.CancellationToken ) { - const params = options.parameters as IFindFilesParameters; + const params = options.input as IFindFilesParameters; let files = await vscode.workspace.findFiles(params.pattern, '**/node_modules/**', undefined, token); if (files.length === 0) { files = await vscode.workspace.findFiles(`**/${params.pattern}`, '**/node_modules/**', undefined, token); @@ -46,7 +46,7 @@ export class FindFilesTool implements vscode.LanguageModelTool, _token: vscode.CancellationToken ) { - const code = sanitizePythonCode(options.parameters.code); - logger.debug(`Executing Python Code for "${options.parameters.reason}"`); + const code = sanitizePythonCode(options.input.code); + logger.debug(`Executing Python Code for "${options.input.reason}"`); logger.debug(`Code => `); logger.debug(code); @@ -121,7 +121,7 @@ export class RunPythonTool implements vscode.LanguageModelTool, _token: vscode.CancellationToken ) { - const reasonMessage = options.parameters.reason ? `: "${options.parameters.reason}"` : ''; + const reasonMessage = options.input.reason ? `: "${options.input.reason}"` : ''; return { invocationMessage: `Executing Code${reasonMessage}` };