-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathinlineChatEditCodePrompt.tsx
More file actions
114 lines (102 loc) · 6.06 KB
/
inlineChatEditCodePrompt.tsx
File metadata and controls
114 lines (102 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { PromptElement, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';
import { ChatLocation } from '../../../../platform/chat/common/commonTypes';
import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService';
import { IIgnoreService } from '../../../../platform/ignore/common/ignoreService';
import { KnownSources } from '../../../../platform/languageServer/common/languageContextService';
import { IParserService } from '../../../../platform/parser/node/parserService';
import { IExperimentationService } from '../../../../platform/telemetry/common/nullExperimentationService';
import { isNotebookCellOrNotebookChatInput } from '../../../../util/common/notebooks';
import { illegalArgument } from '../../../../util/vs/base/common/errors';
import { GenericInlinePromptProps } from '../../../context/node/resolvers/genericInlineIntentInvocation';
import { SelectionSplitKind, SummarizedDocumentData, SummarizedDocumentWithSelection } from '../../../intents/node/testIntent/summarizedDocumentWithSelection';
import { EarlyStopping, LeadingMarkdownStreaming } from '../../../prompt/node/intents';
import { TextPieceClassifiers } from '../../../prompt/node/streamingEdits';
import { InstructionMessage } from '../base/instructionMessage';
import { LegacySafetyRules } from '../base/safetyRules';
import { Tag } from '../base/tag';
import { ChatToolReferences, ChatVariables, UserQuery } from '../panel/chatVariables';
import { HistoryWithInstructions } from '../panel/conversationHistory';
import { CustomInstructions } from '../panel/customInstructions';
import { ProjectLabels } from '../panel/projectLabels';
import { LanguageServerContextPrompt } from './languageServerContextPrompt';
import { SummarizedDocumentSplit } from './promptingSummarizedDocument';
import { TemporalContext } from './temporalContext';
export interface InlineChatEditCodePromptProps extends GenericInlinePromptProps {
}
export class InlineChatEditCodePrompt extends PromptElement<InlineChatEditCodePromptProps> {
constructor(
props: InlineChatEditCodePromptProps,
@IIgnoreService private readonly _ignoreService: IIgnoreService,
@IParserService private readonly _parserService: IParserService,
@IExperimentationService private readonly _experimentationService: IExperimentationService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
) {
super(props);
}
async render(state: void, sizing: PromptSizing) {
const context = this.props.documentContext;
const document = context.document;
const languageId = document.languageId;
if (isNotebookCellOrNotebookChatInput(document.uri)) {
throw illegalArgument('InlineChatEditCodePrompt should not be used with a notebook!');
}
if (languageId === 'markdown') {
throw illegalArgument('InlineChatEditCodePrompt should not be used with a markdown document!');
}
const isIgnored = await this._ignoreService.isCopilotIgnored(document.uri);
if (isIgnored) {
return <ignoredFiles value={[document.uri]} />;
}
const { query, history, chatVariables, } = this.props.promptContext;
const useProjectLabels = this._configurationService.getExperimentBasedConfig(ConfigKey.Internal.ProjectLabelsInline, this._experimentationService);
const data = await SummarizedDocumentData.create(this._parserService, document, context.fileIndentInfo, context.wholeRange, SelectionSplitKind.Adjusted);
const replyInterpreterFactory = (splitDoc: SummarizedDocumentSplit) => splitDoc.createReplyInterpreter(
LeadingMarkdownStreaming.Mute,
EarlyStopping.StopAfterFirstCodeBlock,
splitDoc.replaceSelectionStreaming,
TextPieceClassifiers.createCodeBlockClassifier(),
line => line.value.trim() !== data.placeholderText,
);
return (
<>
<SystemMessage priority={1000}>
You are an AI programming assistant.<br />
When asked for your name, you must respond with "GitHub Copilot".<br />
You are a world class expert in programming, and especially good at {languageId}.<br />
<LegacySafetyRules />
</SystemMessage>
<HistoryWithInstructions inline={true} historyPriority={700} passPriority history={history}>
<InstructionMessage priority={1000}>
Source code is always contained in ``` blocks.<br />
The user needs help to modify some code.<br />
{data.hasCodeWithoutSelection && <>The user includes existing code and marks with {data.placeholderText} where the selected code should go.<br /></>}
</InstructionMessage>
</HistoryWithInstructions>
{useProjectLabels && <ProjectLabels priority={600} embeddedInsideUserMessage={false} />}
<UserMessage>
<CustomInstructions priority={725} chatVariables={chatVariables} languageId={languageId} />
<LanguageServerContextPrompt priority={700} document={document} position={context.selection.start} requestId={this.props.promptContext.requestId} source={KnownSources.chat} />
<TemporalContext priority={600} context={[document]} location={ChatLocation.Editor} />
</UserMessage>
<ChatToolReferences priority={750} promptContext={this.props.promptContext} flexGrow={1} embeddedInsideUserMessage={false} />
<ChatVariables priority={750} chatVariables={chatVariables} embeddedInsideUserMessage={false} />
<UserMessage priority={900} flexGrow={2} flexReserve={sizing.endpoint.modelMaxPromptTokens / 3}>
<SummarizedDocumentWithSelection
flexGrow={1}
tokenBudget={'usePromptSizingBudget'}
documentData={data}
createReplyInterpreter={replyInterpreterFactory}
/>
<Tag name='userPrompt'>
<UserQuery chatVariables={chatVariables} query={query} /><br />
</Tag>
{data.hasCodeWithoutSelection && <>The modified {data.placeholderText} code with ``` is:</>}
</UserMessage>
</>
);
}
}