Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/panelChatBasePrompt.tsx
13405 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 { PromptElement, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';
7
import { ChatLocation } from '../../../../platform/chat/common/commonTypes';
8
import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService';
9
import { IEnvService } from '../../../../platform/env/common/envService';
10
import { IExperimentationService } from '../../../../platform/telemetry/common/nullExperimentationService';
11
import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';
12
import { ToolName } from '../../../tools/common/toolNames';
13
import { Capabilities } from '../base/capabilities';
14
import { CopilotIdentityRules } from '../base/copilotIdentity';
15
import { InstructionMessage } from '../base/instructionMessage';
16
import { ResponseTranslationRules } from '../base/responseTranslationRules';
17
import { SafetyRules } from '../base/safetyRules';
18
import { Tag } from '../base/tag';
19
import { ChatToolReferences, ChatVariablesAndQuery } from './chatVariables';
20
import { CodeBlockFormattingRules } from './codeBlockFormattingRules';
21
import { HistoryWithInstructions } from './conversationHistory';
22
import { CustomInstructions } from './customInstructions';
23
import { ProjectLabels } from './projectLabels';
24
import { WorkspaceFoldersHint } from './workspace/workspaceFoldersHint';
25
26
export interface PanelChatBasePromptProps extends GenericBasePromptElementProps {
27
}
28
29
export class PanelChatBasePrompt extends PromptElement<PanelChatBasePromptProps> {
30
constructor(
31
props: PanelChatBasePromptProps,
32
@IEnvService private readonly envService: IEnvService,
33
@IExperimentationService private readonly experimentationService: IExperimentationService,
34
@IConfigurationService private readonly _configurationService: IConfigurationService,
35
) {
36
super(props);
37
}
38
39
async render(state: void, sizing: PromptSizing) {
40
const { query, history, chatVariables, } = this.props.promptContext;
41
const useProjectLabels = this._configurationService.getExperimentBasedConfig(ConfigKey.Advanced.ProjectLabelsChat, this.experimentationService);
42
const operatingSystem = this.envService.OS;
43
44
return (
45
<>
46
<SystemMessage priority={1000}>
47
You are an AI programming assistant.<br />
48
<CopilotIdentityRules />
49
<SafetyRules />
50
<Capabilities location={ChatLocation.Panel} />
51
<WorkspaceFoldersHint flexGrow={1} priority={800} />
52
{/* 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 */}
53
{!this.envService.isSimulation() && <><br />The current date is {new Date().toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' })}.</>}
54
</SystemMessage>
55
<HistoryWithInstructions flexGrow={1} historyPriority={700} passPriority history={history} currentTurnVars={chatVariables}>
56
<InstructionMessage priority={1000}>
57
Use Markdown formatting in your answers.<br />
58
<CodeBlockFormattingRules />
59
For code blocks use four backticks to start and end.<br />
60
Avoid wrapping the whole response in triple backticks.<br />
61
The 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 />
62
The user is working on a {operatingSystem} machine. Please respond with system specific commands if applicable.<br />
63
The active document is the source code the user is looking at right now.<br />
64
You can only give one reply for each conversation turn.<br />
65
<ResponseTranslationRules />
66
<br />
67
{this.props.promptContext.tools?.toolReferences.find((tool) => tool.name === ToolName.Codebase)
68
? <Tag name='codebaseToolInstructions'>
69
1. 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 />
70
2. 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".
71
</Tag>
72
: undefined}
73
</InstructionMessage>
74
</HistoryWithInstructions>
75
<UserMessage flexGrow={2}>
76
{useProjectLabels && <ProjectLabels flexGrow={1} priority={600} />}
77
<CustomInstructions flexGrow={1} priority={750} languageId={undefined} chatVariables={chatVariables} />
78
<ChatToolReferences priority={899} flexGrow={2} promptContext={this.props.promptContext} />
79
<ChatVariablesAndQuery flexGrow={3} flexReserve='/3' priority={900} chatVariables={chatVariables} query={query} includeFilepath={true} />
80
</UserMessage>
81
</>
82
);
83
}
84
}
85
86