Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/onboardDebug/node/languageToolsProvider.tsx
13399 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 { BasePromptElementProps, PromptElement, PromptPiece, PromptSizing, SystemMessage, TextChunk, UserMessage } from '@vscode/prompt-tsx';
7
import { ChatFetchResponseType, ChatLocation } from '../../../platform/chat/common/commonTypes';
8
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
9
import { createServiceIdentifier } from '../../../util/common/services';
10
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
11
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
12
import { PromptRenderer } from '../../prompts/node/base/promptRenderer';
13
14
// Extracts the "yam" from "- yam" or "yam" or "* yam" 🍠
15
const LIST_RE = /\s*(?:. )?([a-z0-9_-]+)\s*/;
16
17
export interface ILanguageToolsProvider {
18
readonly _serviceBrand: undefined;
19
20
getToolsForLanguages(languages: string[], token: CancellationToken): Promise<{ ok: boolean; commands: string[] }>;
21
}
22
23
export const ILanguageToolsProvider = createServiceIdentifier<ILanguageToolsProvider>('ILanguageToolsProvider');
24
25
export class LanguageToolsProvider {
26
constructor(
27
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
28
@IInstantiationService private readonly instantiationService: IInstantiationService
29
) {
30
}
31
32
public async getToolsForLanguages(languages: string[], token: CancellationToken) {
33
const endpoint = await this.endpointProvider.getChatEndpoint('copilot-base');
34
const promptRenderer = PromptRenderer.create(
35
this.instantiationService,
36
endpoint,
37
ToolLanguagesPrompt,
38
{ languages }
39
);
40
41
const prompt = await promptRenderer.render(undefined, token);
42
const fetchResult = await endpoint.makeChatRequest(
43
'debugCommandIdentifier',
44
prompt.messages,
45
undefined,
46
token,
47
ChatLocation.Other
48
);
49
50
if (fetchResult.type !== ChatFetchResponseType.Success) {
51
return { ok: false, commands: [] };
52
}
53
54
return {
55
ok: true,
56
commands: fetchResult.value
57
.split('\n')
58
.map(s => LIST_RE.exec(s)?.[1])
59
.filter((s): s is string => !!s),
60
};
61
}
62
}
63
64
65
class ToolLanguagesPrompt extends PromptElement<{ languages: string[] } & BasePromptElementProps, void> {
66
override render(_state: void, _sizing: PromptSizing): PromptPiece {
67
return (
68
<>
69
<SystemMessage priority={10}>
70
You are an AI programming assistant that is specialized for usage of command-line tools developers use to build software.<br />
71
I'm working on software in the given following languages. Please list the names of common command-line tools I might use to build and test my software.<br />
72
Do NOT list tools that don't run my code, such as those used only for linting. For example, if I ask for JavaScript, the list should include tools like node, npx, and mocha, but not eslint.<br />
73
Be thorough! Try to give a list of *at least* 10 such tools.<br />
74
Print these tools out as a list, separated by commas. Do NOT print any additional explanation or context.
75
<br />
76
<TextChunk priority={8}>
77
# Example<br />
78
## User: <br />
79
- python<br />
80
- rust<br />
81
## Response:<br />
82
- python<br />
83
- pip<br />
84
- cargo<br />
85
- rustc<br />
86
</TextChunk>
87
</SystemMessage>
88
<UserMessage priority={9}>
89
<TextChunk breakOnWhitespace flexGrow={1}>
90
The languages I'm working in are:<br />
91
{this.props.languages.join('\n -')}
92
</TextChunk>
93
</UserMessage>
94
</>
95
);
96
}
97
}
98
99