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