Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/panelChatFixPrompt.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 { ILanguageDiagnosticsService } from '../../../../platform/languages/common/languageDiagnosticsService';
9
import { findDiagnosticForSelectionAndPrompt } from '../../../context/node/resolvers/fixSelection';
10
import { GenericBasePromptElementProps } from '../../../context/node/resolvers/genericPanelIntentInvocation';
11
import { IDocumentContext } from '../../../prompt/node/documentContext';
12
import { Capabilities } from '../base/capabilities';
13
import { InstructionMessage } from '../base/instructionMessage';
14
import { ResponseTranslationRules } from '../base/responseTranslationRules';
15
import { SafetyRules } from '../base/safetyRules';
16
import { Diagnostics } from '../inline/diagnosticsContext';
17
import { ChatToolReferences, ChatVariablesAndQuery } from './chatVariables';
18
import { CodeBlockFormattingRules } from './codeBlockFormattingRules';
19
import { HistoryWithInstructions } from './conversationHistory';
20
import { CustomInstructions } from './customInstructions';
21
import { ChatToolCalls } from './toolCalling';
22
23
export interface PanelChatFixPromptProps extends GenericBasePromptElementProps {
24
}
25
26
export class PanelChatFixPrompt extends PromptElement<PanelChatFixPromptProps> {
27
28
constructor(props: PanelChatFixPromptProps,
29
@ILanguageDiagnosticsService private readonly languageDiagnosticsService: ILanguageDiagnosticsService
30
) {
31
super(props);
32
}
33
34
render(state: void, sizing: PromptSizing) {
35
const documentContext = this.props.documentContext;
36
const { history, chatVariables, } = this.props.promptContext;
37
const query = this.props.promptContext.query || 'There is a problem in this code. Rewrite the code to show it with the bug fixed.';
38
const getDiagnostics = ({ document, selection }: IDocumentContext) => findDiagnosticForSelectionAndPrompt(this.languageDiagnosticsService, document.uri, selection, query);
39
return (
40
<>
41
<SystemMessage priority={1000}>
42
You are an AI programming assistant.<br />
43
When asked for your name, you must respond with "GitHub Copilot".<br />
44
Follow the user's requirements carefully & to the letter.<br />
45
<SafetyRules />
46
<br />
47
<br />
48
<Capabilities location={ChatLocation.Panel} />
49
</SystemMessage>
50
<HistoryWithInstructions flexGrow={1} passPriority historyPriority={700} history={history}>
51
<InstructionMessage priority={1000}>
52
First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.<br />
53
Then output the code in a single code block.<br />
54
Minimize any other prose.<br />
55
Use Markdown formatting in your answers.<br />
56
<CodeBlockFormattingRules />
57
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 />
58
The active document is the source code the user is looking at right now.<br />
59
You can only give one reply for each conversation turn.<br />
60
<br />
61
Additional Rules<br />
62
You specialize in being a highly skilled code generator. Your task is to help the Developer fix an issue.<br />
63
If context is provided, try to match the style of the provided code as best as possible.<br />
64
Generated code is readable and properly indented.<br />
65
Markdown blocks are used to denote code.<br />
66
Preserve user's code comment blocks, do not exclude them when refactoring code.<br />
67
Pay especially close attention to the selection or exception context.<br />
68
Given a description of what to do you can refactor, fix or enhance the existing code.
69
<ResponseTranslationRules />
70
</InstructionMessage>
71
</HistoryWithInstructions>
72
<UserMessage flexGrow={1} priority={750}>
73
<CustomInstructions languageId={documentContext?.language.languageId} chatVariables={chatVariables} />
74
</UserMessage>
75
{
76
documentContext &&
77
<UserMessage flexGrow={1} priority={800}>
78
<Diagnostics documentContext={documentContext} diagnostics={getDiagnostics(documentContext)} />
79
</UserMessage>
80
}
81
{/* todo@connor4312/roblou: is this the right thing to do here? */}
82
{<ChatToolCalls priority={899} flexGrow={2} promptContext={this.props.promptContext} toolCallRounds={this.props.promptContext.toolCallRounds} toolCallResults={this.props.promptContext.toolCallResults} />}
83
{<ChatToolReferences priority={899} flexGrow={2} promptContext={this.props.promptContext} embeddedInsideUserMessage={false} />}
84
<ChatVariablesAndQuery flexGrow={2} priority={900} chatVariables={chatVariables} query={query} embeddedInsideUserMessage={false} />
85
</>
86
);
87
}
88
}
89
90