Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current author into the issue summarization #6394

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lm/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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<any> = {
parameters,
requestPrompt: request.prompt,
toolInvocationToken: request.toolInvocationToken
};
console.log('invocationOptions : ', invocationOptions);
toolCalls.push({
call: part,
result: vscode.lm.invokeTool(tool.name, invocationOptions, token),
Expand Down
15 changes: 11 additions & 4 deletions src/lm/tools/summarizeIssueTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FetchIssueResult> {
public static readonly toolId = 'github-pull-request_issue_summarize';

constructor(private readonly _credentialStore: CredentialStore) { }

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchIssueResult>): Promise<vscode.PreparedToolInvocation> {
if (!options.parameters.title) {
return {
Expand All @@ -24,7 +28,7 @@ export class IssueSummarizationTool implements vscode.LanguageModelTool<FetchIss
};
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchIssueResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
async invoke(options: ToolInvocationOptions<FetchIssueResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
let issueOrPullRequestInfo: string = `
Title : ${options.parameters.title}
Body : ${options.parameters.body}
Expand Down Expand Up @@ -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, {});
Expand All @@ -67,11 +72,13 @@ Body: ${comment.body}
}
}

private summarizeInstructions(): string {
private async summarizeInstructions(): Promise<string> {
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.
Expand Down
14 changes: 10 additions & 4 deletions src/lm/tools/summarizeNotificationsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FetchNotificationResult> {
public static readonly toolId = 'github-pull-request_notification_summarize';

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchNotificationResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
constructor(private readonly _credentialStore: CredentialStore) { }

async invoke(options: ToolInvocationOptions<FetchNotificationResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
let notificationInfo: string = '';
const lastReadAt = options.parameters.lastReadAt;
if (!lastReadAt) {
Expand Down Expand Up @@ -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, {});
Expand All @@ -77,10 +81,12 @@ Body: ${comment.body}
}
}

private summarizeInstructions(): string {
private async summarizeInstructions(): Promise<string> {
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".
Expand Down
8 changes: 4 additions & 4 deletions src/lm/tools/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/lm/tools/toolsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ export interface IssueResult {
}[];
}

export interface ToolInvocationOptions<T> extends vscode.LanguageModelToolInvocationOptions<T> {
requestPrompt: string;
}

export abstract class ToolBase<T> implements vscode.LanguageModelTool<T> {
constructor(protected readonly chatParticipantState: ChatParticipantState) { }
abstract invoke(options: vscode.LanguageModelToolInvocationOptions<T>, token: vscode.CancellationToken): vscode.ProviderResult<vscode.LanguageModelToolResult>;
abstract invoke(options: ToolInvocationOptions<T>, token: vscode.CancellationToken): vscode.ProviderResult<vscode.LanguageModelToolResult>;
}

export async function concatAsyncIterable(asyncIterable: AsyncIterable<string>): Promise<string> {
Expand Down