diff --git a/src/lm/participants.ts b/src/lm/participants.ts index e5f123cb9e..7b18577d7a 100644 --- a/src/lm/participants.ts +++ b/src/lm/participants.ts @@ -8,7 +8,7 @@ import { renderPrompt } from '@vscode/prompt-tsx'; import * as vscode from 'vscode'; import { dispose } from '../common/utils'; import { ParticipantsPrompt } from './participantsPrompt'; -import { IToolCall, TOOL_COMMAND_RESULT, TOOL_MARKDOWN_RESULT } from './tools/toolsUtils'; +import { IToolCall, TOOL_COMMAND_RESULT, TOOL_MARKDOWN_RESULT, ToolInvocationOptions } from './tools/toolsUtils'; export class ChatParticipantState { private _messages: vscode.LanguageModelChatMessage[] = []; @@ -140,7 +140,12 @@ export class ChatParticipant implements vscode.Disposable { throw new Error(`Got invalid tool use parameters: "${JSON.stringify(part.parameters)}". (${(err as Error).message})`); } - const invocationOptions = { parameters, toolInvocationToken: request.toolInvocationToken, requestedContentTypes: ['text/plain', 'text/markdown', 'text/json', 'text/display', 'command'] }; + const invocationOptions: ToolInvocationOptions = { + parameters, + requestPrompt: request.prompt, + toolInvocationToken: request.toolInvocationToken + }; + console.log('invocationOptions : ', invocationOptions); toolCalls.push({ call: part, result: vscode.lm.invokeTool(tool.name, invocationOptions, token), diff --git a/src/lm/tools/summarizeIssueTool.ts b/src/lm/tools/summarizeIssueTool.ts index ce2d3b3c14..7f8743209f 100644 --- a/src/lm/tools/summarizeIssueTool.ts +++ b/src/lm/tools/summarizeIssueTool.ts @@ -5,12 +5,16 @@ 'use strict'; import * as vscode from 'vscode'; +import { AuthProvider } from '../../common/authentication'; +import { CredentialStore } from '../../github/credentials'; import { FetchIssueResult } from './fetchIssueTool'; -import { concatAsyncIterable } from './toolsUtils'; +import { concatAsyncIterable, ToolInvocationOptions } from './toolsUtils'; export class IssueSummarizationTool implements vscode.LanguageModelTool { public static readonly toolId = 'github-pull-request_issue_summarize'; + constructor(private readonly _credentialStore: CredentialStore) { } + async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions): Promise { if (!options.parameters.title) { return { @@ -24,7 +28,7 @@ export class IssueSummarizationTool implements vscode.LanguageModelTool, _token: vscode.CancellationToken): Promise { + async invoke(options: ToolInvocationOptions, _token: vscode.CancellationToken): Promise { let issueOrPullRequestInfo: string = ` Title : ${options.parameters.title} Body : ${options.parameters.body} @@ -56,7 +60,8 @@ Body: ${comment.body} const model = models[0]; if (model) { - const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions())]; + console.log('options ; ', options); + const messages = [vscode.LanguageModelChatMessage.User(await this.summarizeInstructions())]; messages.push(vscode.LanguageModelChatMessage.User(`The issue or pull request information is as follows:`)); messages.push(vscode.LanguageModelChatMessage.User(issueOrPullRequestInfo)); const response = await model.sendRequest(messages, {}); @@ -67,11 +72,13 @@ Body: ${comment.body} } } - private summarizeInstructions(): string { + private async summarizeInstructions(): Promise { + const userLogin = (await this._credentialStore.getCurrentUser(AuthProvider.github)).login; return ` You are an AI assistant who is very proficient in summarizing issues and PRs. You will be given information relative to an issue or PR : the title, the body and the comments. In the case of a PR you will also be given patches of the PR changes. Your task is to output a summary of all this information. +The user asking you for a summary has login ${userLogin}. Do not output code. When you try to summarize PR changes, summarize in a textual format. When you summarize comments, give a summary of each comment and mention the author clearly. Make sure the summary is at least as short or shorter than the issue or PR with the comments and the patches if there are. diff --git a/src/lm/tools/summarizeNotificationsTool.ts b/src/lm/tools/summarizeNotificationsTool.ts index 0a13fecef2..82b78898bb 100644 --- a/src/lm/tools/summarizeNotificationsTool.ts +++ b/src/lm/tools/summarizeNotificationsTool.ts @@ -5,13 +5,17 @@ 'use strict'; import * as vscode from 'vscode'; +import { AuthProvider } from '../../common/authentication'; +import { CredentialStore } from '../../github/credentials'; import { FetchNotificationResult } from './fetchNotificationTool'; -import { concatAsyncIterable, TOOL_COMMAND_RESULT } from './toolsUtils'; +import { concatAsyncIterable, TOOL_COMMAND_RESULT, ToolInvocationOptions } from './toolsUtils'; export class NotificationSummarizationTool implements vscode.LanguageModelTool { public static readonly toolId = 'github-pull-request_notification_summarize'; - async invoke(options: vscode.LanguageModelToolInvocationOptions, _token: vscode.CancellationToken): Promise { + constructor(private readonly _credentialStore: CredentialStore) { } + + async invoke(options: ToolInvocationOptions, _token: vscode.CancellationToken): Promise { let notificationInfo: string = ''; const lastReadAt = options.parameters.lastReadAt; if (!lastReadAt) { @@ -61,7 +65,7 @@ Body: ${comment.body} }] }; if (model) { - const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions())]; + const messages = [vscode.LanguageModelChatMessage.User(await this.summarizeInstructions())]; messages.push(vscode.LanguageModelChatMessage.User(`The notification information is as follows:`)); messages.push(vscode.LanguageModelChatMessage.User(notificationInfo)); const response = await model.sendRequest(messages, {}); @@ -77,10 +81,12 @@ Body: ${comment.body} } } - private summarizeInstructions(): string { + private async summarizeInstructions(): Promise { + const userLogin = (await this._credentialStore.getCurrentUser(AuthProvider.github)).login; return ` You are an AI assistant who is very proficient in summarizing notification threads. You will be given information relative to a notification thread : the title, the body and the comments. In the case of a PR you will also be given patches of the PR changes. +The current user login is ${userLogin}. Since you are reviewing a notification thread, part of the content is by definition unread. You will be told what part of the content is yet unread. This can be the comments or it can be both the thread issue/PR as well as the comments. Your task is to output a summary of all this notification thread information and give an update to the user concerning the unread part of the thread. Always include in your output, which part of the thread is unread by prefixing that part with the markdown heading of level 1 with text "Unread Thread" or "Unread Comments". diff --git a/src/lm/tools/tools.ts b/src/lm/tools/tools.ts index ef16886544..148e8cca10 100644 --- a/src/lm/tools/tools.ts +++ b/src/lm/tools/tools.ts @@ -18,7 +18,7 @@ import { NotificationSummarizationTool } from './summarizeNotificationsTool'; export function registerTools(context: vscode.ExtensionContext, credentialStore: CredentialStore, repositoriesManager: RepositoriesManager, chatParticipantState: ChatParticipantState) { registerFetchingTools(context, credentialStore, repositoriesManager, chatParticipantState); - registerSummarizationTools(context); + registerSummarizationTools(context, credentialStore); registerSuggestFixTool(context, credentialStore, repositoriesManager, chatParticipantState); registerSearchTools(context, credentialStore, repositoriesManager, chatParticipantState); } @@ -28,9 +28,9 @@ function registerFetchingTools(context: vscode.ExtensionContext, credentialStore context.subscriptions.push(vscode.lm.registerTool(FetchNotificationTool.toolId, new FetchNotificationTool(credentialStore, repositoriesManager, chatParticipantState))); } -function registerSummarizationTools(context: vscode.ExtensionContext) { - context.subscriptions.push(vscode.lm.registerTool(IssueSummarizationTool.toolId, new IssueSummarizationTool())); - context.subscriptions.push(vscode.lm.registerTool(NotificationSummarizationTool.toolId, new NotificationSummarizationTool())); +function registerSummarizationTools(context: vscode.ExtensionContext, credentialStore: CredentialStore) { + context.subscriptions.push(vscode.lm.registerTool(IssueSummarizationTool.toolId, new IssueSummarizationTool(credentialStore))); + context.subscriptions.push(vscode.lm.registerTool(NotificationSummarizationTool.toolId, new NotificationSummarizationTool(credentialStore))); } function registerSuggestFixTool(context: vscode.ExtensionContext, credentialStore: CredentialStore, repositoriesManager: RepositoriesManager, chatParticipantState: ChatParticipantState) { diff --git a/src/lm/tools/toolsUtils.ts b/src/lm/tools/toolsUtils.ts index ec0e4304e9..15f1a9f840 100644 --- a/src/lm/tools/toolsUtils.ts +++ b/src/lm/tools/toolsUtils.ts @@ -36,9 +36,13 @@ export interface IssueResult { }[]; } +export interface ToolInvocationOptions extends vscode.LanguageModelToolInvocationOptions { + requestPrompt: string; +} + export abstract class ToolBase implements vscode.LanguageModelTool { constructor(protected readonly chatParticipantState: ChatParticipantState) { } - abstract invoke(options: vscode.LanguageModelToolInvocationOptions, token: vscode.CancellationToken): vscode.ProviderResult; + abstract invoke(options: ToolInvocationOptions, token: vscode.CancellationToken): vscode.ProviderResult; } export async function concatAsyncIterable(asyncIterable: AsyncIterable): Promise {