diff --git a/packages/vscode-extension/package.nls.json b/packages/vscode-extension/package.nls.json index 2bb2c8a471..f95c770f70 100644 --- a/packages/vscode-extension/package.nls.json +++ b/packages/vscode-extension/package.nls.json @@ -468,7 +468,7 @@ "teamstoolkit.chatParticipants.nextStep.whatsNext": "What should I do next?", "teamstoolkit.chatParticipants.create.sample": "Scaffold this sample", "teamstoolkit.chatParticipants.create.template": "Create this template", - "teamstoolkit.chatParticipants.create.tooGeneric": "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a chat bot', you could specify 'create a chat bot that answers FAQs for customer support.'", + "teamstoolkit.chatParticipants.create.tooGeneric": "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a bot', you could specify 'create a bot template' or 'create a notification bot that sends user the stock updates'.", "teamstoolkit.chatParticipants.create.oneMatched": "We've found 1 project that matches your description. Take a look at it below.\n\n", "teamstoolkit.chatParticipants.create.multipleMatched": "We've found %d projects that match your description. Take a look at them below.\n", "teamstoolkit.chatParticipants.create.noMatched": "I cannot find any matching templates or samples. Refine your app description or explore other templates.", diff --git a/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts b/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts index 17115a6730..8fc2c88413 100644 --- a/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts +++ b/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts @@ -95,8 +95,11 @@ declare module 'vscode' { * console.error(e); * } * ``` + * + * To cancel the stream, the consumer can {@link CancellationTokenSource.cancel cancel} the token that was used to make the request + * or break from the for-loop. */ - stream: AsyncIterable; + text: AsyncIterable; } /** diff --git a/packages/vscode-extension/src/chat/commands/create/helper.ts b/packages/vscode-extension/src/chat/commands/create/helper.ts index c170855340..117de68ecd 100644 --- a/packages/vscode-extension/src/chat/commands/create/helper.ts +++ b/packages/vscode-extension/src/chat/commands/create/helper.ts @@ -45,8 +45,11 @@ export async function matchProject( if (!request.prompt.includes("template")) { // also search in samples matchedProjects.push(...(await matchSamples(request, token, telemetryMetadata))); + matchedProjects.sort((a, b) => b.score - a.score); + } else { + matchedProjects.sort((a, b) => b.score - a.score); + matchedProjects.splice(2); } - matchedProjects.sort((a, b) => b.score - a.score); const result: ProjectMetadata[] = []; const matchedProjectIds = new Set(); for (const { id, score } of matchedProjects) { diff --git a/packages/vscode-extension/src/chat/utils.ts b/packages/vscode-extension/src/chat/utils.ts index 6e3608a68e..445f814a72 100644 --- a/packages/vscode-extension/src/chat/utils.ts +++ b/packages/vscode-extension/src/chat/utils.ts @@ -19,8 +19,8 @@ export async function verbatimCopilotInteraction( if (!familyMatch) { throw new Error("No chat models available for the specified family"); } - const chatRequest = await familyMatch.sendRequest(messages, {}, token); - for await (const fragment of chatRequest.stream) { + const chatResponse = await familyMatch.sendRequest(messages, {}, token); + for await (const fragment of chatResponse.text) { response.markdown(fragment); } } @@ -36,9 +36,9 @@ export async function getCopilotResponseAsString( if (!familyMatch) { throw new Error("No chat models available for the specified family"); } - const chatRequest = await familyMatch.sendRequest(messages, {}, token); + const chatResponse = await familyMatch.sendRequest(messages, {}, token); let response = ""; - for await (const fragment of chatRequest.stream) { + for await (const fragment of chatResponse.text) { response += fragment; } return response; diff --git a/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts b/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts index e4b074f145..112d5acad7 100644 --- a/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts +++ b/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts @@ -282,7 +282,7 @@ describe("chat create command", () => { chai.assert.isTrue(showFileTreeStub.notCalled); chai.assert.isTrue( response.markdown.calledOnceWith( - "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a chat bot', you could specify 'create a chat bot that answers FAQs for customer support.'" + "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a bot', you could specify 'create a bot template' or 'create a notification bot that sends user the stock updates'." ) ); }); diff --git a/packages/vscode-extension/test/chat/commands/create/helper.test.ts b/packages/vscode-extension/test/chat/commands/create/helper.test.ts index 36f88861f9..eee8bf179b 100644 --- a/packages/vscode-extension/test/chat/commands/create/helper.test.ts +++ b/packages/vscode-extension/test/chat/commands/create/helper.test.ts @@ -65,6 +65,47 @@ describe("chat create helper", () => { chai.assert.strictEqual(result.length, 1); chai.assert.strictEqual(result[0].id, "test1"); }); + + it("has matched template project", async () => { + const chatTelemetryDataMock = sandbox.createStubInstance(telemetry.ChatTelemetryData); + sandbox.stub(chatTelemetryDataMock, "properties").get(function getterFn() { + return undefined; + }); + sandbox.stub(chatTelemetryDataMock, "measurements").get(function getterFn() { + return undefined; + }); + sandbox.stub(sampleProvider, "SampleCollection").get(function getterFn() { + return { + samples: [ + { + id: "test1", + title: "test1", + fullDescription: "test1", + }, + ], + }; + }); + chatTelemetryDataMock.chatMessages = []; + sandbox + .stub(telemetry.ChatTelemetryData, "createByParticipant") + .returns(chatTelemetryDataMock); + const sendTelemetryEventStub = sandbox.stub(ExtTelemetry, "sendTelemetryEvent"); + sandbox + .stub(util, "getCopilotResponseAsString") + .onFirstCall() + .resolves('{"app":[{"id": "bot", "score": 1.0}]}') + .onSecondCall() + .resolves('{"app":[{"id": "test2", "score": 0.5}]}'); + + const token = new CancellationToken(); + const result = await helper.matchProject( + { prompt: "test template" } as vscode.ChatRequest, + token, + chatTelemetryDataMock + ); + chai.assert.strictEqual(result.length, 1); + chai.assert.strictEqual(result[0].id, "bot"); + }); }); describe("showFileTree()", () => { diff --git a/packages/vscode-extension/test/chat/utils.test.ts b/packages/vscode-extension/test/chat/utils.test.ts index ef61a5ebc5..11e22b97ea 100644 --- a/packages/vscode-extension/test/chat/utils.test.ts +++ b/packages/vscode-extension/test/chat/utils.test.ts @@ -30,7 +30,7 @@ describe("chat utils", () => { const token = new CancellationToken(); const chatModel: vscode.LanguageModelChat = { sendRequest: sandbox.stub().resolves({ - stream: asyncIterator, + text: asyncIterator, }), id: "", vendor: "", @@ -77,7 +77,7 @@ describe("chat utils", () => { const token = new CancellationToken(); const chatModel: vscode.LanguageModelChat = { sendRequest: sandbox.stub().resolves({ - stream: asyncIterator, + text: asyncIterator, }), id: "", vendor: "", diff --git a/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts b/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts index 41be59a043..ff903f65f8 100644 --- a/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts +++ b/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts @@ -75,7 +75,7 @@ export async function getCopilotResponseAsString( } const chatRequest = await familyMatch.sendRequest(messages, {}, token); let response = ""; - for await (const fragment of chatRequest.stream) { + for await (const fragment of chatRequest.text) { response += fragment; } return response;