Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/e2e/vscode-metaprompt.stest.ts
13388 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ChatVariablesCollection } from '../../src/extension/prompt/common/chatVariablesCollection';
8
import { VscodePrompt } from '../../src/extension/prompts/node/panel/vscode';
9
import { IEndpointProvider } from '../../src/platform/endpoint/common/endpointProvider';
10
import { CancellationToken } from '../../src/util/vs/base/common/cancellation';
11
import { IInstantiationService } from '../../src/util/vs/platform/instantiation/common/instantiation';
12
import { ssuite, stest } from '../base/stest';
13
14
ssuite.skip({ title: 'vscode', subtitle: 'metaprompt', location: 'panel' }, async (_) => {
15
16
const scenarios = [
17
{
18
question: 'how to opne command pallete',
19
keywords: ['open', 'command palette'],
20
excludedKeywords: ['how',]
21
},
22
{
23
question: 'how do I change font size setting',
24
keywords: ['setting', 'font size'],
25
excludedKeywords: ['how',]
26
},
27
{
28
question: 'enable word wrap in editer',
29
keywords: ['enable', 'editor', 'word wrap'],
30
excludedKeywords: []
31
},
32
];
33
34
for (const scenario of scenarios) {
35
stest({ description: scenario.question },
36
async (testingServiceCollection) => {
37
const accessor = testingServiceCollection.createTestingAccessor();
38
const instantiationService = accessor.get(IInstantiationService);
39
40
const endpoint = await accessor.get(IEndpointProvider).getChatEndpoint('copilot-base');
41
const vscodePrompt = instantiationService.createInstance(VscodePrompt, {
42
promptContext: {
43
chatVariables: new ChatVariablesCollection([]),
44
history: [],
45
query: scenario.question,
46
},
47
endpoint
48
});
49
50
const tokenizer = endpoint.acquireTokenizer();
51
const countTokens = (text: string) => tokenizer.tokenLength(text);
52
53
const prompt = await vscodePrompt.prepare({ tokenBudget: 2048, endpoint, countTokens }, undefined, CancellationToken.None);
54
assert.notEqual(prompt.query, scenario.question);
55
56
for (const keyword of scenario.keywords) {
57
assert.ok(prompt.query.toLowerCase().includes(keyword.toLowerCase()), `${keyword} not found in prompt query`);
58
}
59
for (const keyword of scenario.excludedKeywords) {
60
assert.ok(!prompt.query.toLowerCase().includes(keyword.toLowerCase()), `prompt query should not include "${keyword}"`);
61
}
62
});
63
}
64
});
65
66