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

fix(chat): string #11505

Merged
merged 9 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
text: AsyncIterable<string>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
for (const { id, score } of matchedProjects) {
Expand Down
8 changes: 4 additions & 4 deletions packages/vscode-extension/src/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-extension/test/chat/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -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: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down