Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/panelChatBasePrompt.tsx
13405 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 { PromptElement, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';6import { ChatLocation } from '../../../../platform/chat/common/commonTypes';7import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService';8import { IEnvService } from '../../../../platform/env/common/envService';9import { IExperimentationService } from '../../../../platform/telemetry/common/nullExperimentationService';10import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';11import { ToolName } from '../../../tools/common/toolNames';12import { Capabilities } from '../base/capabilities';13import { CopilotIdentityRules } from '../base/copilotIdentity';14import { InstructionMessage } from '../base/instructionMessage';15import { ResponseTranslationRules } from '../base/responseTranslationRules';16import { SafetyRules } from '../base/safetyRules';17import { Tag } from '../base/tag';18import { ChatToolReferences, ChatVariablesAndQuery } from './chatVariables';19import { CodeBlockFormattingRules } from './codeBlockFormattingRules';20import { HistoryWithInstructions } from './conversationHistory';21import { CustomInstructions } from './customInstructions';22import { ProjectLabels } from './projectLabels';23import { WorkspaceFoldersHint } from './workspace/workspaceFoldersHint';2425export interface PanelChatBasePromptProps extends GenericBasePromptElementProps {26}2728export class PanelChatBasePrompt extends PromptElement<PanelChatBasePromptProps> {29constructor(30props: PanelChatBasePromptProps,31@IEnvService private readonly envService: IEnvService,32@IExperimentationService private readonly experimentationService: IExperimentationService,33@IConfigurationService private readonly _configurationService: IConfigurationService,34) {35super(props);36}3738async render(state: void, sizing: PromptSizing) {39const { query, history, chatVariables, } = this.props.promptContext;40const useProjectLabels = this._configurationService.getExperimentBasedConfig(ConfigKey.Advanced.ProjectLabelsChat, this.experimentationService);41const operatingSystem = this.envService.OS;4243return (44<>45<SystemMessage priority={1000}>46You are an AI programming assistant.<br />47<CopilotIdentityRules />48<SafetyRules />49<Capabilities location={ChatLocation.Panel} />50<WorkspaceFoldersHint flexGrow={1} priority={800} />51{/* Only include current date when not running simulations, since if we generate cache entries with the current date, the cache will be invalidated every day */}52{!this.envService.isSimulation() && <><br />The current date is {new Date().toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' })}.</>}53</SystemMessage>54<HistoryWithInstructions flexGrow={1} historyPriority={700} passPriority history={history} currentTurnVars={chatVariables}>55<InstructionMessage priority={1000}>56Use Markdown formatting in your answers.<br />57<CodeBlockFormattingRules />58For code blocks use four backticks to start and end.<br />59Avoid wrapping the whole response in triple backticks.<br />60The user works in an IDE called Visual Studio Code which has a concept for editors with open files, integrated unit test support, an output pane that shows the output of running the code as well as an integrated terminal.<br />61The user is working on a {operatingSystem} machine. Please respond with system specific commands if applicable.<br />62The active document is the source code the user is looking at right now.<br />63You can only give one reply for each conversation turn.<br />64<ResponseTranslationRules />65<br />66{this.props.promptContext.tools?.toolReferences.find((tool) => tool.name === ToolName.Codebase)67? <Tag name='codebaseToolInstructions'>681. Consider how to answer the user's prompt based on the provided information. Always assume that the user is asking about the code in their workspace instead of asking a general programming question. Prefer using variables, functions, types, and classes from the workspace over those from the standard library.<br />692. Generate a response that clearly and accurately answers the user's question. In your response, add fully qualified links for referenced symbols (example: [`namespace.VariableName`](path/to/file.ts)) and links for files (example: [path/to/file](path/to/file.ts)) so that the user can open them. If you do not have enough information to answer the question, respond with "I'm sorry, I can't answer that question with what I currently know about your workspace".70</Tag>71: undefined}72</InstructionMessage>73</HistoryWithInstructions>74<UserMessage flexGrow={2}>75{useProjectLabels && <ProjectLabels flexGrow={1} priority={600} />}76<CustomInstructions flexGrow={1} priority={750} languageId={undefined} chatVariables={chatVariables} />77<ChatToolReferences priority={899} flexGrow={2} promptContext={this.props.promptContext} />78<ChatVariablesAndQuery flexGrow={3} flexReserve='/3' priority={900} chatVariables={chatVariables} query={query} includeFilepath={true} />79</UserMessage>80</>81);82}83}848586