From 2ae584e8c8f262039172aa2e2588a26257650a52 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 26 Nov 2024 16:33:27 -0800 Subject: [PATCH 1/3] improv: restore multiline stops --- core/autocomplete/templating/getStopTokens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/autocomplete/templating/getStopTokens.ts b/core/autocomplete/templating/getStopTokens.ts index fffb5351b..18c5887a3 100644 --- a/core/autocomplete/templating/getStopTokens.ts +++ b/core/autocomplete/templating/getStopTokens.ts @@ -20,7 +20,7 @@ export function getStopTokens( ): string[] { const stopTokens = [ ...(completionOptions?.stop || []), - // ...multilineStops, + ...multilineStops, ...commonStops, ...(model.toLowerCase().includes("starcoder2") ? STARCODER2_T_ARTIFACTS From f98117d7d24ac7667651150d8994fe666a18621d Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 27 Nov 2024 14:14:34 -0800 Subject: [PATCH 2/3] improv: add multiline soft stop --- .../StreamTransformPipeline.ts | 4 +- .../filtering/streamTransforms/lineStream.ts | 38 +---- core/autocomplete/filtering/test/testCases.ts | 132 +++++++++--------- 3 files changed, 72 insertions(+), 102 deletions(-) diff --git a/core/autocomplete/filtering/streamTransforms/StreamTransformPipeline.ts b/core/autocomplete/filtering/streamTransforms/StreamTransformPipeline.ts index da178cb66..55cde067a 100644 --- a/core/autocomplete/filtering/streamTransforms/StreamTransformPipeline.ts +++ b/core/autocomplete/filtering/streamTransforms/StreamTransformPipeline.ts @@ -6,7 +6,7 @@ import { stopAtStartOf, stopAtStopTokens } from "./charStream"; import { avoidEmptyComments, avoidPathLine, - noDoubleNewlineAfterClosingBracket, + noDoubleNewLine, showWhateverWeHaveAtXMs, skipPrefixes, stopAtLines, @@ -49,7 +49,7 @@ export class StreamTransformPipeline { ); lineGenerator = avoidPathLine(lineGenerator, helper.lang.singleLineComment); lineGenerator = skipPrefixes(lineGenerator); - lineGenerator = noDoubleNewlineAfterClosingBracket(lineGenerator); + lineGenerator = noDoubleNewLine(lineGenerator); for (const lineFilter of helper.lang.lineFilters ?? []) { lineGenerator = lineFilter({ lines: lineGenerator, fullStop }); diff --git a/core/autocomplete/filtering/streamTransforms/lineStream.ts b/core/autocomplete/filtering/streamTransforms/lineStream.ts index 9cbf190ec..9b344ec6e 100644 --- a/core/autocomplete/filtering/streamTransforms/lineStream.ts +++ b/core/autocomplete/filtering/streamTransforms/lineStream.ts @@ -548,42 +548,16 @@ export async function* showWhateverWeHaveAtXMs( } } -export async function* noDoubleNewlineAfterClosingBracket( - lines: LineStream, -): LineStream { - const bracketTypeCounts = new Map(); +export async function* noDoubleNewLine(lines: LineStream): LineStream { + let isFirstLine = true; for await (const line of lines) { - if (line.trim() === "") { - // Double newline detected - // Check if any bracket counts are negative - let hasNegativeCount = false; - for (const count of bracketTypeCounts.values()) { - if (count < 0) { - hasNegativeCount = true; - break; - } - } - if (hasNegativeCount) { - // Stop the generator if we've closed brackets we didn't open - return; - } + if (line.trim() === "" && !isFirstLine) { + return; } + isFirstLine = false; + yield line; - - // Update bracket counts - for (const char of line) { - if (BRACKETS[char]) { - // It's an opening bracket - const count = bracketTypeCounts.get(char) || 0; - bracketTypeCounts.set(char, count + 1); - } else if (BRACKETS_REVERSE[char]) { - // It's a closing bracket - const openingBracket = BRACKETS_REVERSE[char]; - const count = bracketTypeCounts.get(openingBracket) || 0; - bracketTypeCounts.set(openingBracket, count - 1); - } - } } } diff --git a/core/autocomplete/filtering/test/testCases.ts b/core/autocomplete/filtering/test/testCases.ts index 33924b1b3..7735269f5 100644 --- a/core/autocomplete/filtering/test/testCases.ts +++ b/core/autocomplete/filtering/test/testCases.ts @@ -110,6 +110,7 @@ Here is a list of features: - Feature 2`, }, { + // options: { only: true }, description: "Should autocomplete a Java method within a class", filename: "Calculator.java", input: ` @@ -150,8 +151,7 @@ public class Calculator { POSTGRES_DB: mydb `, expectedCompletion: ` - POSTGRES_DB: mydb - `, + POSTGRES_DB: mydb`, }, { description: @@ -283,8 +283,7 @@ async getContextForPath( ): Promise { const snippets: AutocompleteCodeSnippet[] = []; `, - expectedCompletion: `console.log('TEST'); - `, + expectedCompletion: `console.log('TEST');`, }, { description: "Should autocomplete React effect hook", @@ -333,6 +332,67 @@ export const Timer = () => { llmOutput: ` this;`, expectedCompletion: `this;`, }, + { + description: "Should complete YAML list item and preserve structure", + filename: "test.yaml", + input: ` + services: + - name: web + image: nginx + - name: app<|fim|> + volumes: + - volume1 + - volume2 + `, + llmOutput: ` + image: node + `, + expectedCompletion: ` + image: node`, + }, + { + description: + "Should complete YAML key-value pair inside a nested structure", + filename: "test.yaml", + input: ` + version: '3' + services: + db: + image: postgres + environment: + POSTGRES_USER: user + POSTGRES_PASSWORD: pass + POSTGRES_DB: mydb<|fim|> + `, + llmOutput: ` + PGDATA: /var/lib/postgresql/data/pgdata + `, + expectedCompletion: ` + PGDATA: /var/lib/postgresql/data/pgdata`, + }, + { + description: "Should complete YAML block within an existing block", + filename: "test.yaml", + input: ` + pipelines: + branches: + master: + - step: + name: Build and Test + script: + - npm install + - npm run test + - step: + name: Deploy<|fim|> + `, + llmOutput: ` + script: + - npm run deploy + `, + expectedCompletion: ` + script: + - npm run deploy`, + }, ]; export const TEST_CASES_WITHOUT_DIFF: AutocompleteFileringTestInput[] = [ @@ -1030,70 +1090,6 @@ Smart<|fim|>`, llmOutput: "ob, 2023-02-10", expectedCompletion: "ob, 2023-02-10", }, - { - description: "Should complete YAML list item and preserve structure", - filename: "test.yaml", - input: ` - services: - - name: web - image: nginx - - name: app<|fim|> - volumes: - - volume1 - - volume2 - `, - llmOutput: ` - image: node - `, - expectedCompletion: ` - image: node - `, - }, - { - description: - "Should complete YAML key-value pair inside a nested structure", - filename: "test.yaml", - input: ` - version: '3' - services: - db: - image: postgres - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: pass - POSTGRES_DB: mydb<|fim|> - `, - llmOutput: ` - PGDATA: /var/lib/postgresql/data/pgdata - `, - expectedCompletion: ` - PGDATA: /var/lib/postgresql/data/pgdata - `, - }, - { - description: "Should complete YAML block within an existing block", - filename: "test.yaml", - input: ` - pipelines: - branches: - master: - - step: - name: Build and Test - script: - - npm install - - npm run test - - step: - name: Deploy<|fim|> - `, - llmOutput: ` - script: - - npm run deploy - `, - expectedCompletion: ` - script: - - npm run deploy - `, - }, { description: "Should autocomplete a Rust function implementation inside a struct", From 620ecbe0cae1539187923c05aa8222ebd2d6088d Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Wed, 27 Nov 2024 14:15:08 -0800 Subject: [PATCH 3/3] imrov: remove multiline stop tokens --- core/autocomplete/templating/getStopTokens.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/autocomplete/templating/getStopTokens.ts b/core/autocomplete/templating/getStopTokens.ts index 18c5887a3..95cbedd21 100644 --- a/core/autocomplete/templating/getStopTokens.ts +++ b/core/autocomplete/templating/getStopTokens.ts @@ -10,7 +10,7 @@ const STARCODER2_T_ARTIFACTS = ["t.", "\nt", ""]; const PYTHON_ENCODING = "#- coding: utf-8"; const CODE_BLOCK_END = "```"; -const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE]; +// const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE]; const commonStops = [SRC_DIRECTORY, PYTHON_ENCODING, CODE_BLOCK_END]; export function getStopTokens( @@ -20,7 +20,7 @@ export function getStopTokens( ): string[] { const stopTokens = [ ...(completionOptions?.stop || []), - ...multilineStops, + // ...multilineStops, ...commonStops, ...(model.toLowerCase().includes("starcoder2") ? STARCODER2_T_ARTIFACTS