Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/inlineChat2/node/progressMessagesPrompt.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, PromptReference, SystemMessage, UserMessage } from '@vscode/prompt-tsx';
7
import type { Uri } from 'vscode';
8
import { SafetyRules } from '../../prompts/node/base/safetyRules';
9
import { ResponseTranslationRules } from '../../prompts/node/base/responseTranslationRules';
10
import { Tag } from '../../prompts/node/base/tag';
11
import { CodeBlock } from '../../prompts/node/panel/safeElements';
12
13
14
export type ProgressMessageScenario = 'generate' | 'edit';
15
16
export interface ProgressMessagesPromptProps extends BasePromptElementProps {
17
readonly scenario: ProgressMessageScenario;
18
readonly count: number;
19
}
20
21
export class ProgressMessagesPrompt extends PromptElement<ProgressMessagesPromptProps> {
22
override render() {
23
const scenarioDescription = this.props.scenario === 'generate'
24
? 'generating new code from scratch based on a user request'
25
: 'editing and improving existing code based on a user request';
26
27
return (
28
<>
29
<SystemMessage priority={1000}>
30
You are an expert in writing short, catchy, and encouraging progress messages for a coding assistant.<br />
31
The messages are shown to users while they wait for an AI to {scenarioDescription}.<br />
32
<br />
33
<SafetyRules />
34
<ResponseTranslationRules />
35
<br />
36
Guidelines for the messages:<br />
37
- Each message should be 2-4 words<br />
38
- Be encouraging and slightly playful<br />
39
- Reference coding/programming themes<br />
40
- Avoid technical jargon that would confuse beginners<br />
41
- Do not use emojis<br />
42
- Do not use punctuation at the end<br />
43
- Each message should be unique and different from the others<br />
44
- Return messages as a JSON array of strings, nothing else<br />
45
<br />
46
Examples of good progress messages:<br />
47
- Warming up the algorithms<br />
48
- Brewing some fresh code<br />
49
- Crafting your solution<br />
50
- Thinking through the logic<br />
51
- Almost there, hang tight<br />
52
</SystemMessage>
53
<UserMessage priority={900}>
54
Please generate exactly {this.props.count} unique progress messages for the "{this.props.scenario} code" scenario.<br />
55
Return only a JSON array of strings, no other text.
56
</UserMessage>
57
</>
58
);
59
}
60
}
61
62
export interface ContextualProgressMessagePromptProps extends BasePromptElementProps {
63
readonly prompt: string;
64
readonly fileName: string;
65
readonly uri: Uri;
66
readonly languageId: string;
67
readonly selectedCode: string | undefined;
68
}
69
70
export class ContextualProgressMessagePrompt extends PromptElement<ContextualProgressMessagePromptProps> {
71
override render() {
72
const scenario = this.props.selectedCode ? 'editing existing code' : 'generating new code';
73
74
return (
75
<>
76
<SystemMessage priority={1000}>
77
You are an expert in writing short, catchy, and encouraging progress messages for a coding assistant.<br />
78
The user is waiting for an AI to help them with {scenario}.<br />
79
<br />
80
<SafetyRules />
81
<ResponseTranslationRules />
82
<br />
83
Guidelines for the message:<br />
84
- The message should be 2-5 words<br />
85
- Make it specific to what the user is trying to do based on their prompt<br />
86
- Be encouraging and slightly playful<br />
87
- You may reference the programming language ({this.props.languageId}) if relevant<br />
88
- Avoid technical jargon that would confuse beginners<br />
89
- Do not use emojis<br />
90
- Do not use punctuation at the end<br />
91
- Return only the message text, nothing else<br />
92
<br />
93
Examples of good contextual progress messages:<br />
94
- For "add a function": Crafting your function<br />
95
- For "fix the bug": Hunting down the bug<br />
96
- For "add comments": Documenting the code<br />
97
- For "refactor this": Polishing your code<br />
98
- For Python file: Pythonizing your logic<br />
99
</SystemMessage>
100
<UserMessage priority={900}>
101
<Tag name='prompt'>{this.props.prompt}</Tag>
102
{this.props.selectedCode
103
? <Tag name='selected-code'>
104
<CodeBlock includeFilepath={true} languageId={this.props.languageId} uri={this.props.uri} references={[new PromptReference(this.props.uri, undefined, undefined)]} code={this.props.selectedCode} />
105
</Tag>
106
: <Tag name='file' attrs={{ name: this.props.fileName }} />
107
}
108
<br />
109
Generate a single short progress message that is specific to this request.
110
</UserMessage>
111
</>
112
);
113
}
114
}
115
116