From 97b2c04f80c84d199ab776501e97aa43e5015c61 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 29 Feb 2024 20:49:49 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20useCache=20customization=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/autocomplete/lineStream.ts | 13 +++++++++++++ core/autocomplete/parameters.ts | 3 ++- core/index.d.ts | 1 + docs/static/schemas/config.json | 10 +++++++--- .../intellij/src/main/resources/config_schema.json | 10 +++++++--- extensions/vscode/config_schema.json | 10 +++++++--- extensions/vscode/continue_rc_schema.json | 14 +++++++++----- extensions/vscode/package-lock.json | 4 ++-- .../vscode/src/autocomplete/getTabCompletion.ts | 5 +++-- 9 files changed, 51 insertions(+), 19 deletions(-) diff --git a/core/autocomplete/lineStream.ts b/core/autocomplete/lineStream.ts index 400705387..9299549dc 100644 --- a/core/autocomplete/lineStream.ts +++ b/core/autocomplete/lineStream.ts @@ -50,6 +50,19 @@ export async function* stopAtSimilarLine( } } +const LINES_TO_STOP_AT = [ + "# End of file." +] + +export async function* stopAtLines(stream: LineStream): LineStream { + for await (const line of stream) { + if (LINES_TO_STOP_AT.includes(line)) { + break; + } + yield line; + } +} + function shouldRemoveLineBeforeStart(line: string): boolean { return ( line.trimStart().startsWith("```") || diff --git a/core/autocomplete/parameters.ts b/core/autocomplete/parameters.ts index 67d4f3b30..2034b7306 100644 --- a/core/autocomplete/parameters.ts +++ b/core/autocomplete/parameters.ts @@ -11,5 +11,6 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = { slidingWindowPrefixPercentage: 0.75, slidingWindowSize: 500, maxSnippetPercentage: 0.6, - recentlyEditedSimilarityThreshold: 0.3 + recentlyEditedSimilarityThreshold: 0.3, + useCache: true }; diff --git a/core/index.d.ts b/core/index.d.ts index b5f807594..6bdecae25 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -590,6 +590,7 @@ export interface TabAutocompleteOptions { slidingWindowSize: number; maxSnippetPercentage: number; recentlyEditedSimilarityThreshold: number; + useCache: boolean; } export interface SerializedContinueConfig { diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 7cc6e3c2f..51fc65340 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1212,9 +1212,9 @@ }, "required": ["name", "type", "connection"] } - } - }, - "required": ["connections"] + }, + "required": ["connections"] + } }, { "if": { @@ -1561,6 +1561,10 @@ "multilineCompletions": { "enum": ["always", "never", "auto"], "description": "If set to true, Continue will only complete a single line at a time." + }, + "useCache": { + "type": "boolean", + "description": "Whether to cache completions" } }, "required": [] diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 7cc6e3c2f..51fc65340 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -1212,9 +1212,9 @@ }, "required": ["name", "type", "connection"] } - } - }, - "required": ["connections"] + }, + "required": ["connections"] + } }, { "if": { @@ -1561,6 +1561,10 @@ "multilineCompletions": { "enum": ["always", "never", "auto"], "description": "If set to true, Continue will only complete a single line at a time." + }, + "useCache": { + "type": "boolean", + "description": "Whether to cache completions" } }, "required": [] diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 7cc6e3c2f..51fc65340 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -1212,9 +1212,9 @@ }, "required": ["name", "type", "connection"] } - } - }, - "required": ["connections"] + }, + "required": ["connections"] + } }, { "if": { @@ -1561,6 +1561,10 @@ "multilineCompletions": { "enum": ["always", "never", "auto"], "description": "If set to true, Continue will only complete a single line at a time." + }, + "useCache": { + "type": "boolean", + "description": "Whether to cache completions" } }, "required": [] diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 857062ff3..362a36908 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -1362,11 +1362,11 @@ "connection" ] } - } - }, - "required": [ - "connections" - ] + }, + "required": [ + "connections" + ] + } }, { "if": { @@ -1756,6 +1756,10 @@ "auto" ], "description": "If set to true, Continue will only complete a single line at a time." + }, + "useCache": { + "type": "boolean", + "description": "Whether to cache completions" } }, "required": [] diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 2860d22c7..7a9ceb840 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.73", + "version": "0.9.74", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.73", + "version": "0.9.74", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/src/autocomplete/getTabCompletion.ts b/extensions/vscode/src/autocomplete/getTabCompletion.ts index f7e126bb8..a6ded1e4d 100644 --- a/extensions/vscode/src/autocomplete/getTabCompletion.ts +++ b/extensions/vscode/src/autocomplete/getTabCompletion.ts @@ -7,6 +7,7 @@ import { } from "core/autocomplete/constructPrompt"; import { avoidPathLine, + stopAtLines, stopAtSimilarLine, streamWithNewLines, } from "core/autocomplete/lineStream"; @@ -112,7 +113,7 @@ export async function getTabCompletion( let completion = ""; const cache = await autocompleteCache; - const cachedCompletion = await cache.get(prompt); + const cachedCompletion = options.useCache ? await cache.get(prompt) : undefined; let cacheHit = false; if (cachedCompletion) { // Cache @@ -159,7 +160,7 @@ export async function getTabCompletion( generatorWithCancellation(), lang.endOfLine ); - const lineGenerator = streamWithNewLines(avoidPathLine(streamLines(gen2), lang.comment)); + const lineGenerator = streamWithNewLines(avoidPathLine(stopAtLines(streamLines(gen2)), lang.comment)); const finalGenerator = stopAtSimilarLine(lineGenerator, lineBelowCursor); for await (const update of finalGenerator) { completion += update;