Skip to content

Commit

Permalink
Work around User message utility issue (#6349)
Browse files Browse the repository at this point in the history
* Work around User message utility issue

* Fix in search tool
  • Loading branch information
alexr00 authored Oct 22, 2024
1 parent 33f3bfa commit bc3eeaf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/lm/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ export class ChatParticipantState {
return [];
}

get firstUserMessage(): string | undefined {
get firstUserMessage(): vscode.LanguageModelTextPart | undefined {
for (let i = 0; i < this._messages.length; i++) {
const message = this._messages[i];
if (message.role === vscode.LanguageModelChatMessageRole.User && message.content) {
return message.content;
for (const part of message.content) {
if (part instanceof vscode.LanguageModelTextPart) {
return part;
}
}
}
}
}
Expand Down Expand Up @@ -96,7 +100,7 @@ export class ChatParticipant implements vscode.Disposable {
{ modelMaxPromptTokens: model.maxInputTokens },
model);

this.state.addMessages(messages);
this.state.addMessages(messages as any);

const toolReferences = [...request.toolReferences];
const options: vscode.LanguageModelChatRequestOptions = {
Expand Down
10 changes: 7 additions & 3 deletions src/lm/tools/displayIssuesTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export class DisplayIssuesTool extends ToolBase<DisplayIssuesParameters> {
return finalColumns;
}

private async getImportantColumns(issueItemsInfo: string, issues: IssueSearchResultItem[], token: vscode.CancellationToken): Promise<IssueColumn[]> {
private async getImportantColumns(issueItemsInfo: vscode.LanguageModelTextPart | undefined, issues: IssueSearchResultItem[], token: vscode.CancellationToken): Promise<IssueColumn[]> {
if (!issueItemsInfo) {
return ['number', 'title', 'state'];
}

// Try to get the llm to tell us which columns are important based on information it has about the issues
const models = await vscode.lm.selectChatModels({
vendor: 'copilot',
Expand All @@ -68,7 +72,7 @@ export class DisplayIssuesTool extends ToolBase<DisplayIssuesParameters> {
justification: 'Answering user questions pertaining to GitHub.'
};
const messages = [vscode.LanguageModelChatMessage.Assistant(this.assistantPrompt(issues))];
messages.push(vscode.LanguageModelChatMessage.User(issueItemsInfo));
messages.push(new vscode.LanguageModelChatMessage(vscode.LanguageModelChatMessageRole.User, issueItemsInfo?.value));
const response = await model.sendRequest(messages, chatOptions, token);
const result = this.postProcess(await concatAsyncIterable(response.text), issues);
const indexOfUrl = result.indexOf('url');
Expand Down Expand Up @@ -119,7 +123,7 @@ export class DisplayIssuesTool extends ToolBase<DisplayIssuesParameters> {
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<DisplayIssuesParameters>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
let issueItemsInfo: string = this.chatParticipantState.firstUserMessage ?? '';
let issueItemsInfo: vscode.LanguageModelTextPart | undefined = this.chatParticipantState.firstUserMessage;
const issueItems: IssueSearchResultItem[] = options.parameters.arrayOfIssues;
if (issueItems.length === 0) {
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(vscode.l10n.t('No issues found. Please try another query.'))]);
Expand Down
2 changes: 1 addition & 1 deletion src/lm/tools/searchTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ You are getting ready to make a GitHub search query. Given a natural language qu

async invoke(options: vscode.LanguageModelToolInvocationOptions<ConvertToQuerySyntaxParameters>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
const { owner, name, folderManager } = this.getRepoInfo({ owner: options.parameters.repo?.owner, name: options.parameters.repo?.name });
const firstUserMessage = `${this.chatParticipantState.firstUserMessage}, ${options.parameters.naturalLanguageString}`;
const firstUserMessage = `${this.chatParticipantState.firstUserMessage?.value}, ${options.parameters.naturalLanguageString}`;

const labels = await folderManager.getLabels(undefined, { owner, repo: name });

Expand Down

0 comments on commit bc3eeaf

Please sign in to comment.