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