⚡️ stop autocomplete model from outputting // Path: ...

This commit is contained in:
Nate Sesti 2024-02-29 11:30:46 -05:00
parent bc7e7d591d
commit c4598b7685
2 changed files with 13 additions and 1 deletions

View file

@ -2,6 +2,17 @@ import { distance } from "fastest-levenshtein";
import { DiffLine } from "..";
import { LineStream } from "../diff/util";
export async function* avoidPathLine(stream: LineStream, comment: string): LineStream {
// Snippets are inserted as comments with a line at the start '// Path: <PATH>'.
// Sometimes the model with copy this pattern, which is unwanted
for await (const line of stream){
if (line.startsWith(comment + " Path: ")) {
continue;
}
yield line;
}
}
export async function* streamWithNewLines(stream: LineStream): LineStream {
let firstLine = true;
for await (const nextLine of stream) {

View file

@ -6,6 +6,7 @@ import {
languageForFilepath,
} from "core/autocomplete/constructPrompt";
import {
avoidPathLine,
stopAtSimilarLine,
streamWithNewLines,
} from "core/autocomplete/lineStream";
@ -158,7 +159,7 @@ export async function getTabCompletion(
generatorWithCancellation(),
lang.endOfLine
);
const lineGenerator = streamWithNewLines(streamLines(gen2));
const lineGenerator = streamWithNewLines(avoidPathLine(streamLines(gen2), lang.comment));
const finalGenerator = stopAtSimilarLine(lineGenerator, lineBelowCursor);
for await (const update of finalGenerator) {
completion += update;