⚡️ strip <COMPLETION> from GPT-4 completion

This commit is contained in:
Nate Sesti 2024-06-16 19:15:22 -07:00
parent 5a7083ba54
commit f97573e77e
2 changed files with 18 additions and 0 deletions

View file

@ -38,6 +38,7 @@ import { AutocompleteLanguageInfo } from "./languages.js";
import {
avoidPathLine,
noTopLevelKeywordsMidline,
skipPrefixes,
stopAtLines,
stopAtRepeatingLines,
stopAtSimilarLine,
@ -407,6 +408,7 @@ export async function getTabCompletion(
lineGenerator = stopAtLines(lineGenerator, fullStop);
lineGenerator = stopAtRepeatingLines(lineGenerator, fullStop);
lineGenerator = avoidPathLine(lineGenerator, lang.singleLineComment);
lineGenerator = skipPrefixes(lineGenerator);
lineGenerator = noTopLevelKeywordsMidline(
lineGenerator,
lang.topLevelKeywords,

View file

@ -121,6 +121,22 @@ export async function* stopAtLines(
}
}
const PREFIXES_TO_SKIP = ["<COMPLETION>"];
export async function* skipPrefixes(lines: LineStream): LineStream {
let isFirstLine = true;
for await (const line of lines) {
if (isFirstLine) {
const match = PREFIXES_TO_SKIP.find((prefix) => line.startsWith(prefix));
if (match) {
yield line.slice(match.length);
continue;
}
isFirstLine = false;
}
yield line;
}
}
const LINES_TO_SKIP = ["</START EDITING HERE>"];
export async function* skipLines(stream: LineStream): LineStream {