Skip to content

Commit 5a79e87

Browse files
authored
nes: support nes_41miniv3 prompt strategy (#262)
* nes: fix prediction field for codexv2.1-nes-3.0.0 * nes: support `nes_41miniv3` prompt strategy
1 parent daed8fc commit 5a79e87

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

src/extension/xtab/common/promptCrafting.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ Your task is to predict and complete the changes the developer would have made n
9797
- Apologize with "Sorry, I can't assist with that." for requests that may breach Microsoft content guidelines.
9898
- Avoid undoing or reverting the developer's last change unless there are obvious typos or errors.`;
9999

100+
export const nes41Miniv3SystemPrompt = `Your role as an AI assistant is to help developers complete their code tasks by assisting in editing specific sections of code marked by the <|code_to_edit|> and <|/code_to_edit|> tags, while adhering to Microsoft's content policies and avoiding the creation of content that violates copyrights.
101+
102+
You have access to the following information to help you make informed suggestions:
103+
104+
- recently_viewed_code_snippets: These are code snippets that the developer has recently looked at, which might provide context or examples relevant to the current task. They are listed from oldest to newest. It's possible these are entirely irrelevant to the developer's change.
105+
- current_file_content: The content of the file the developer is currently working on, providing the broader context of the code.
106+
- edit_diff_history: A record of changes made to the code, helping you understand the evolution of the code and the developer's intentions. These changes are listed from oldest to latest. It's possible a lot of old edit diff history is entirely irrelevant to the developer's change.
107+
- area_around_code_to_edit: The context showing the code surrounding the section to be edited.
108+
- cursor position marked as <|cursor|>: Indicates where the developer's cursor is currently located, which can be crucial for understanding what part of the code they are focusing on.
109+
110+
Your task is to predict and complete the changes the developer would have made next in the <|code_to_edit|> section. The developer may have stopped in the middle of typing. Your goal is to keep the developer on the path that you think they're following. Some examples include further implementing a class, method, or variable, or improving the quality of the code. Make sure the developer doesn't get distracted and ensure your suggestion is relevant. Consider what changes need to be made next, if any. If you think changes should be made, ask yourself if this is truly what needs to happen. If you are confident about it, then proceed with the changes.
111+
112+
# Steps
113+
114+
1. **Review Context**: Analyze the context from the resources provided, such as recently viewed snippets, edit history, surrounding code, and cursor location.
115+
2. **Evaluate Current Code**: Determine if the current code within the tags requires any corrections or enhancements.
116+
3. **Suggest Edits**: If changes are required, ensure they align with the developer's patterns and improve code quality.
117+
4. **Maintain Consistency**: Ensure indentation and formatting follow the existing code style.
118+
119+
# Output Format
120+
- Your response should start with the word <EDIT> or <NO_CHANGE>.
121+
- If your are making an edit, start with <EDIT>, then provide the rewritten code window, then </EDIT>.
122+
- If no changes are necessary, reply only with <NO_CHANGE>.
123+
- Ensure that you do not output duplicate code that exists outside of these tags. The output should be the revised code that was between these tags and should not include the <|code_to_edit|> or <|/code_to_edit|> tags.
124+
125+
# Notes
126+
127+
- Apologize with "Sorry, I can't assist with that." for requests that may breach Microsoft content guidelines.
128+
- Avoid undoing or reverting the developer's last change unless there are obvious typos or errors.`;
129+
100130
export const simplifiedPrompt = 'Predict next code edit based on the context given by the user.';
101131

102132
export const xtab275SystemPrompt = `Predict the next code edit based on user context, following Microsoft content policies and avoiding copyright violations. If a request may breach guidelines, reply: "Sorry, I can't assist with that."`;
@@ -128,8 +158,7 @@ they would have made next. Provide the revised code that was between the \`${COD
128158
// Your revised code goes here
129159
\`\`\``);
130160

131-
return `
132-
\`\`\`
161+
return `${opts.promptingStrategy === PromptingStrategy.Nes41Miniv3 ? '' : '```'}
133162
${RECENTLY_VIEWED_CODE_SNIPPETS_START}
134163
${recentlyViewedCodeSnippets}
135164
${RECENTLY_VIEWED_CODE_SNIPPETS_END}
@@ -143,8 +172,7 @@ ${EDIT_DIFF_HISTORY_START_TAG}
143172
${editDiffHistory}
144173
${EDIT_DIFF_HISTORY_END_TAG}
145174
146-
${areaAroundCodeToEdit}
147-
\`\`\`
175+
${areaAroundCodeToEdit}${opts.promptingStrategy === PromptingStrategy.Nes41Miniv3 ? '' : '\n```'}
148176
149177
${postScript}
150178
`.trim();

src/extension/xtab/node/xtabProvider.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { Delayer, DelaySession } from '../../inlineEdits/common/delayer';
4242
import { editWouldDeleteWhatWasJustInserted } from '../../inlineEdits/common/ghNearbyNesProvider';
4343
import { getOrDeduceSelectionFromLastEdit } from '../../inlineEdits/common/nearbyCursorInlineEditProvider';
4444
import { IgnoreImportChangesAspect } from '../../inlineEdits/node/importFiltering';
45-
import { AREA_AROUND_END_TAG, AREA_AROUND_START_TAG, CODE_TO_EDIT_END_TAG, CODE_TO_EDIT_START_TAG, createTaggedCurrentFileContentUsingPagedClipping, CURSOR_TAG, getUserPrompt, N_LINES_ABOVE, N_LINES_AS_CONTEXT, N_LINES_BELOW, simplifiedPrompt, systemPromptTemplate, unifiedModelSystemPrompt, xtab275SystemPrompt } from '../common/promptCrafting';
45+
import { AREA_AROUND_END_TAG, AREA_AROUND_START_TAG, CODE_TO_EDIT_END_TAG, CODE_TO_EDIT_START_TAG, createTaggedCurrentFileContentUsingPagedClipping, CURSOR_TAG, getUserPrompt, N_LINES_ABOVE, N_LINES_AS_CONTEXT, N_LINES_BELOW, nes41Miniv3SystemPrompt, simplifiedPrompt, systemPromptTemplate, unifiedModelSystemPrompt, xtab275SystemPrompt } from '../common/promptCrafting';
4646
import { XtabEndpoint } from './xtabEndpoint';
4747
import { linesWithBackticksRemoved, toLines } from './xtabUtils';
4848

@@ -219,6 +219,7 @@ export class XtabProvider extends ChainedStatelessNextEditProvider {
219219
isCodexV21NesUnified: this.configService.getExperimentBasedConfig(ConfigKey.Internal.InlineEditsXtabCodexV21NesUnified, this.expService),
220220
useSimplifiedPrompt: this.configService.getExperimentBasedConfig(ConfigKey.Internal.InlineEditsXtabProviderUseSimplifiedPrompt, this.expService),
221221
useXtab275Prompting: this.configService.getExperimentBasedConfig(ConfigKey.Internal.InlineEditsXtabProviderUseXtab275Prompting, this.expService),
222+
useNes41Miniv3Prompting: this.configService.getExperimentBasedConfig(ConfigKey.Internal.InlineEditsXtabUseNes41Miniv3Prompting, this.expService),
222223
});
223224
promptOptions = {
224225
promptingStrategy,
@@ -783,7 +784,7 @@ export class XtabProvider extends ChainedStatelessNextEditProvider {
783784
}
784785
}
785786

786-
private determinePromptingStrategy({ isXtabUnifiedModel, isCodexV21NesUnified, useSimplifiedPrompt, useXtab275Prompting }: { isXtabUnifiedModel: boolean; isCodexV21NesUnified: boolean; useSimplifiedPrompt: boolean; useXtab275Prompting: boolean }): xtabPromptOptions.PromptingStrategy | undefined {
787+
private determinePromptingStrategy({ isXtabUnifiedModel, isCodexV21NesUnified, useSimplifiedPrompt, useXtab275Prompting, useNes41Miniv3Prompting }: { isXtabUnifiedModel: boolean; isCodexV21NesUnified: boolean; useSimplifiedPrompt: boolean; useXtab275Prompting: boolean; useNes41Miniv3Prompting: boolean }): xtabPromptOptions.PromptingStrategy | undefined {
787788
if (isXtabUnifiedModel) {
788789
return xtabPromptOptions.PromptingStrategy.UnifiedModel;
789790
} else if (isCodexV21NesUnified) {
@@ -792,6 +793,8 @@ export class XtabProvider extends ChainedStatelessNextEditProvider {
792793
return xtabPromptOptions.PromptingStrategy.SimplifiedSystemPrompt;
793794
} else if (useXtab275Prompting) {
794795
return xtabPromptOptions.PromptingStrategy.Xtab275;
796+
} else if (useNes41Miniv3Prompting) {
797+
return xtabPromptOptions.PromptingStrategy.Nes41Miniv3;
795798
} else {
796799
return undefined;
797800
}
@@ -806,6 +809,8 @@ export class XtabProvider extends ChainedStatelessNextEditProvider {
806809
return simplifiedPrompt;
807810
case xtabPromptOptions.PromptingStrategy.Xtab275:
808811
return xtab275SystemPrompt;
812+
case xtabPromptOptions.PromptingStrategy.Nes41Miniv3:
813+
return nes41Miniv3SystemPrompt;
809814
default:
810815
return systemPromptTemplate;
811816
}
@@ -838,7 +843,8 @@ export class XtabProvider extends ChainedStatelessNextEditProvider {
838843

839844
private static getPredictionContents(editWindowLines: readonly string[], promptingStrategy: xtabPromptOptions.PromptingStrategy | undefined): string {
840845
if (promptingStrategy === xtabPromptOptions.PromptingStrategy.UnifiedModel ||
841-
promptingStrategy === xtabPromptOptions.PromptingStrategy.Codexv21NesUnified
846+
promptingStrategy === xtabPromptOptions.PromptingStrategy.Codexv21NesUnified ||
847+
promptingStrategy === xtabPromptOptions.PromptingStrategy.Nes41Miniv3
842848
) {
843849
return ['<EDIT>', ...editWindowLines, '</EDIT>'].join('\n');
844850
} else if (promptingStrategy === xtabPromptOptions.PromptingStrategy.Xtab275) {

src/platform/configuration/common/configurationService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ export namespace ConfigKey {
679679
export const InlineEditsXtabUseUnifiedModel = defineExpSetting<boolean>('chat.advanced.inlineEdits.xtabProvider.useUnifiedModel', false, INTERNAL_RESTRICTED);
680680
export const InlineEditsXtabProviderUseSimplifiedPrompt = defineExpSetting<boolean>('chat.advanced.inlineEdits.xtabProvider.simplifiedPrompt', false, INTERNAL_RESTRICTED);
681681
export const InlineEditsXtabProviderUseXtab275Prompting = defineExpSetting<boolean>('chat.advanced.inlineEdits.xtabProvider.xtab275Prompting', false, INTERNAL_RESTRICTED);
682+
export const InlineEditsXtabUseNes41Miniv3Prompting = defineExpSetting<boolean>('chat.advanced.inlineEdits.xtabProvider.useNes41Miniv3Prompting', false, INTERNAL_RESTRICTED);
682683
export const InlineEditsXtabCodexV21NesUnified = defineExpSetting<boolean>('chat.advanced.inlineEdits.xtabProvider.codexv21nesUnified', false, INTERNAL_RESTRICTED);
683684
export const InlineEditsDiagnosticsExplorationEnabled = defineSetting<boolean | undefined>('chat.advanced.inlineEdits.inlineEditsDiagnosticsExplorationEnabled', false, INTERNAL_RESTRICTED);
684685
export const EditSourceTrackingEnabled = defineSetting('chat.advanced.editSourceTracking.enabled', true, INTERNAL);

src/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ export type PromptOptions = {
3737
readonly diffHistory: DiffHistoryOptions;
3838
}
3939

40+
/**
41+
* Prompt strategies that tweak prompt in a way that's different from current prod prompting strategy.
42+
*/
4043
export enum PromptingStrategy {
4144
/**
4245
* Original Xtab unified model prompting strategy.
4346
*/
4447
UnifiedModel = 'xtabUnifiedModel',
4548
Codexv21NesUnified = 'codexv21nesUnified',
49+
Nes41Miniv3 = 'nes41miniv3',
4650
SimplifiedSystemPrompt = 'simplifiedSystemPrompt',
4751
Xtab275 = 'xtab275',
4852
}

0 commit comments

Comments
 (0)