Skip to content

Commit d39c37f

Browse files
authored
nes: refactor: more sane way to tweak response format (microsoft#1709)
1 parent 99ac8c8 commit d39c37f

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

src/extension/xtab/node/xtabProvider.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ export class XtabProvider implements IStatelessNextEditProvider {
322322

323323
const userPrompt = getUserPrompt(promptPieces);
324324

325-
const prediction = this.getPredictedOutput(editWindowLines, promptOptions.promptingStrategy);
325+
const responseFormat = xtabPromptOptions.ResponseFormat.fromPromptingStrategy(promptOptions.promptingStrategy);
326+
327+
const prediction = this.getPredictedOutput(editWindowLines, responseFormat);
326328

327329
const messages = constructMessages({
328330
systemMsg: this.pickSystemPrompt(promptOptions.promptingStrategy),
@@ -361,7 +363,7 @@ export class XtabProvider implements IStatelessNextEditProvider {
361363
{
362364
showLabel: opts.showLabel,
363365
shouldRemoveCursorTagFromResponse,
364-
promptingStrategy: promptOptions.promptingStrategy,
366+
responseFormat,
365367
retryState,
366368
},
367369
delaySession,
@@ -563,7 +565,7 @@ export class XtabProvider implements IStatelessNextEditProvider {
563565
prediction: Prediction | undefined,
564566
opts: {
565567
showLabel: boolean;
566-
promptingStrategy: xtabPromptOptions.PromptingStrategy | undefined;
568+
responseFormat: xtabPromptOptions.ResponseFormat;
567569
shouldRemoveCursorTagFromResponse: boolean;
568570
retryState: RetryState;
569571
},
@@ -687,13 +689,9 @@ export class XtabProvider implements IStatelessNextEditProvider {
687689

688690
let cleanedLinesStream: AsyncIterableObject<string>;
689691

690-
if (opts.promptingStrategy === xtabPromptOptions.PromptingStrategy.Xtab275) {
692+
if (opts.responseFormat === xtabPromptOptions.ResponseFormat.EditWindowOnly) {
691693
cleanedLinesStream = linesStream;
692-
} else if (
693-
opts.promptingStrategy === xtabPromptOptions.PromptingStrategy.UnifiedModel ||
694-
opts.promptingStrategy === xtabPromptOptions.PromptingStrategy.Codexv21NesUnified ||
695-
opts.promptingStrategy === xtabPromptOptions.PromptingStrategy.Nes41Miniv3
696-
) {
694+
} else if (opts.responseFormat === xtabPromptOptions.ResponseFormat.UnifiedWithXml) {
697695
const linesIter = linesStream[Symbol.asyncIterator]();
698696
const firstLine = await linesIter.next();
699697

@@ -765,8 +763,10 @@ export class XtabProvider implements IStatelessNextEditProvider {
765763
pushEdit(Result.error(new NoNextEditReason.Unexpected(new Error(`unexpected tag ${trimmedLines}`))));
766764
return;
767765
}
768-
} else {
766+
} else if (opts.responseFormat === xtabPromptOptions.ResponseFormat.CodeBlock) {
769767
cleanedLinesStream = linesWithBackticksRemoved(linesStream);
768+
} else {
769+
assertNever(opts.responseFormat);
770770
}
771771

772772
const diffOptions: ResponseProcessor.DiffParams = {
@@ -1316,25 +1316,24 @@ export class XtabProvider implements IStatelessNextEditProvider {
13161316
return createProxyXtabEndpoint(this.instaService, configuredModelName);
13171317
}
13181318

1319-
private getPredictedOutput(editWindowLines: string[], promptingStrategy: xtabPromptOptions.PromptingStrategy | undefined): Prediction | undefined {
1319+
private getPredictedOutput(editWindowLines: string[], responseFormat: xtabPromptOptions.ResponseFormat): Prediction | undefined {
13201320
return this.configService.getConfig(ConfigKey.Internal.InlineEditsXtabProviderUsePrediction)
13211321
? {
13221322
type: 'content',
1323-
content: XtabProvider.getPredictionContents(editWindowLines, promptingStrategy)
1323+
content: XtabProvider.getPredictionContents(editWindowLines, responseFormat)
13241324
}
13251325
: undefined;
13261326
}
13271327

1328-
private static getPredictionContents(editWindowLines: readonly string[], promptingStrategy: xtabPromptOptions.PromptingStrategy | undefined): string {
1329-
if (promptingStrategy === xtabPromptOptions.PromptingStrategy.UnifiedModel ||
1330-
promptingStrategy === xtabPromptOptions.PromptingStrategy.Codexv21NesUnified ||
1331-
promptingStrategy === xtabPromptOptions.PromptingStrategy.Nes41Miniv3
1332-
) {
1328+
private static getPredictionContents(editWindowLines: readonly string[], responseFormat: xtabPromptOptions.ResponseFormat): string {
1329+
if (responseFormat === xtabPromptOptions.ResponseFormat.UnifiedWithXml) {
13331330
return ['<EDIT>', ...editWindowLines, '</EDIT>'].join('\n');
1334-
} else if (promptingStrategy === xtabPromptOptions.PromptingStrategy.Xtab275) {
1331+
} else if (responseFormat === xtabPromptOptions.ResponseFormat.EditWindowOnly) {
13351332
return editWindowLines.join('\n');
1336-
} else {
1333+
} else if (responseFormat === xtabPromptOptions.ResponseFormat.CodeBlock) {
13371334
return ['```', ...editWindowLines, '```'].join('\n');
1335+
} else {
1336+
assertNever(responseFormat);
13381337
}
13391338
}
13401339

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { assertNever } from '../../../../util/vs/base/common/assert';
67
import { vBoolean, vEnum, vObj, vRequired, vString, vUndefined, vUnion } from '../../../configuration/common/validator';
78

89
export type RecentlyViewedDocumentsOptions = {
@@ -57,6 +58,30 @@ export enum PromptingStrategy {
5758
Xtab275 = 'xtab275',
5859
}
5960

61+
export enum ResponseFormat {
62+
CodeBlock = 'codeBlock',
63+
UnifiedWithXml = 'unifiedWithXml',
64+
EditWindowOnly = 'editWindowOnly',
65+
}
66+
67+
export namespace ResponseFormat {
68+
export function fromPromptingStrategy(strategy: PromptingStrategy | undefined): ResponseFormat {
69+
switch (strategy) {
70+
case PromptingStrategy.UnifiedModel:
71+
case PromptingStrategy.Codexv21NesUnified:
72+
case PromptingStrategy.Nes41Miniv3:
73+
return ResponseFormat.UnifiedWithXml;
74+
case PromptingStrategy.Xtab275:
75+
return ResponseFormat.EditWindowOnly;
76+
case PromptingStrategy.SimplifiedSystemPrompt:
77+
case undefined:
78+
return ResponseFormat.CodeBlock;
79+
default:
80+
assertNever(strategy);
81+
}
82+
}
83+
}
84+
6085
export const DEFAULT_OPTIONS: PromptOptions = {
6186
promptingStrategy: undefined,
6287
currentFile: {

0 commit comments

Comments
 (0)