diff --git a/chat-tools-sample/src/extension.ts b/chat-tools-sample/src/extension.ts index e368129e..2c668ce3 100644 --- a/chat-tools-sample/src/extension.ts +++ b/chat-tools-sample/src/extension.ts @@ -14,7 +14,7 @@ function registerChatTool(context: vscode.ExtensionContext) { interface IToolCall { tool: vscode.LanguageModelToolDescription; - call: vscode.LanguageModelChatResponseToolCallPart; + call: vscode.LanguageModelToolCallPart; result: Thenable; } @@ -72,9 +72,9 @@ function registerChatParticipant(context: vscode.ExtensionContext) { const response = await model.sendRequest(messages, options, token); for await (const part of response.stream) { - if (part instanceof vscode.LanguageModelChatResponseTextPart) { + if (part instanceof vscode.LanguageModelTextPart) { stream.markdown(part.value); - } else if (part instanceof vscode.LanguageModelChatResponseToolCallPart) { + } else if (part instanceof vscode.LanguageModelToolCallPart) { const tool = vscode.lm.tools.find(tool => tool.id === part.name); if (!tool) { // BAD tool choice? @@ -100,13 +100,13 @@ function registerChatParticipant(context: vscode.ExtensionContext) { if (toolCalls.length) { const assistantMsg = vscode.LanguageModelChatMessage.Assistant(''); - assistantMsg.content2 = toolCalls.map(toolCall => new vscode.LanguageModelChatResponseToolCallPart(toolCall.tool.id, toolCall.call.toolCallId, toolCall.call.parameters)); + assistantMsg.content2 = toolCalls.map(toolCall => new vscode.LanguageModelToolCallPart(toolCall.tool.id, toolCall.call.toolCallId, toolCall.call.parameters)); messages.push(assistantMsg); for (const toolCall of toolCalls) { // NOTE that the result of calling a function is a special content type of a USER-message const message = vscode.LanguageModelChatMessage.User(''); - message.content2 = [new vscode.LanguageModelChatMessageToolResultPart(toolCall.call.toolCallId, (await toolCall.result)['text/plain']!)]; + message.content2 = [new vscode.LanguageModelToolResultPart(toolCall.call.toolCallId, (await toolCall.result)['text/plain']!)]; messages.push(message); } diff --git a/chat-tools-sample/vscode.proposed.lmTools.d.ts b/chat-tools-sample/vscode.proposed.lmTools.d.ts index 5f12e3df..c5ecb486 100644 --- a/chat-tools-sample/vscode.proposed.lmTools.d.ts +++ b/chat-tools-sample/vscode.proposed.lmTools.d.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// version: 7 +// version: 8 // https://github.com/microsoft/vscode/issues/213274 declare module 'vscode' { @@ -30,7 +30,7 @@ declare module 'vscode' { } // LM -> USER: function that should be used - export class LanguageModelChatResponseToolCallPart { + export class LanguageModelToolCallPart { name: string; toolCallId: string; parameters: any; @@ -39,24 +39,23 @@ declare module 'vscode' { } // LM -> USER: text chunk - export class LanguageModelChatResponseTextPart { + export class LanguageModelTextPart { value: string; constructor(value: string); } export interface LanguageModelChatResponse { - stream: AsyncIterable; + stream: AsyncIterable; } // USER -> LM: the result of a function call - export class LanguageModelChatMessageToolResultPart { + export class LanguageModelToolResultPart { toolCallId: string; content: string; - isError: boolean; - constructor(toolCallId: string, content: string, isError?: boolean); + constructor(toolCallId: string, content: string); } export interface LanguageModelChatMessage { @@ -65,10 +64,10 @@ declare module 'vscode' { * Some parts would be message-type specific for some models and wouldn't go together, * but it's up to the chat provider to decide what to do about that. * Can drop parts that are not valid for the message type. - * LanguageModelChatMessageToolResultPart: only on User messages - * LanguageModelChatResponseToolCallPart: only on Assistant messages + * LanguageModelToolResultPart: only on User messages + * LanguageModelToolCallPart: only on Assistant messages */ - content2: (string | LanguageModelChatMessageToolResultPart | LanguageModelChatResponseToolCallPart)[]; + content2: (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[]; } // Tool registration/invoking between extensions @@ -76,25 +75,23 @@ declare module 'vscode' { /** * A result returned from a tool invocation. */ + // TODO@API should we align this with NotebookCellOutput and NotebookCellOutputItem export interface LanguageModelToolResult { /** * The result can contain arbitrary representations of the content. A tool user can set * {@link LanguageModelToolInvocationOptions.requested} to request particular types, and a tool implementation should only - * compute the types that were requested. `text/plain` is required to be supported by all tools. Another example might be - * a `PromptElementJSON` from `@vscode/prompt-tsx`, using the `contentType` exported by that library. + * compute the types that were requested. `text/plain` is recommended to be supported by all tools, which would indicate + * any text-based content. Another example might be a `PromptElementJSON` from `@vscode/prompt-tsx`, using the + * `contentType` exported by that library. */ [contentType: string]: any; - - /** - * A string representation of the result. - */ - 'text/plain'?: string; } export namespace lm { /** * Register a LanguageModelTool. The tool must also be registered in the package.json `languageModelTools` contribution - * point. A registered tool is available in the {@link lm.tools} list for any extension to invoke. + * point. A registered tool is available in the {@link lm.tools} list for any extension to see. But in order for it to + * be seen by a language model, it must be passed in the list of available tools in {@link LanguageModelChatRequestOptions.tools}. */ export function registerTool(id: string, tool: LanguageModelTool): Disposable; @@ -134,7 +131,7 @@ declare module 'vscode' { /** * A tool user can request that particular content types be returned from the tool, depending on what the tool user - * supports. All tools are required to support `text/plain`. See {@link LanguageModelToolResult}. + * supports. All tools are recommended to support `text/plain`. See {@link LanguageModelToolResult}. */ requestedContentTypes: string[];