From cbd258390133e5d4152763f7ab1d3fc8dc25ce6a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 2 Jan 2024 11:07:46 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20allow=20setting=20promptTemplates?= =?UTF-8?q?=20in=20config.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/commands/slash/edit.ts | 2 +- core/config/types.ts | 15 +++++++++ core/index.d.ts | 1 + core/llm/index.ts | 2 +- .../vscode/manual-testing-sandbox/example.ts | 33 +++++++++++++++++-- .../vscode/src/terminal/terminalEmulator.ts | 6 ++-- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index c9abec151..3c2f76cdf 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -414,7 +414,7 @@ const EditSlashCommand: SlashCommand = { let lineBelowHighlightedRange = fileSuffix.trim().split("\n")[0]; // Use custom templates defined by the model - const template = llm.promptTemplates?.["edit"]; + const template = llm.promptTemplates?.edit; let generator: AsyncGenerator; if (template) { let rendered = renderPromptTemplate( diff --git a/core/config/types.ts b/core/config/types.ts index 5256b7e97..7f22b468f 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -112,6 +112,7 @@ declare global { temperature?: number; topP?: number; topK?: number; + minP?: number; presencePenalty?: number; frequencyPenalty?: number; stop?: string[]; @@ -166,6 +167,7 @@ declare global { temperature?: number; topP?: number; topK?: number; + minP?: number; presencePenalty?: number; frequencyPenalty?: number; stop?: string[]; @@ -229,6 +231,11 @@ declare global { // IDE + export interface DiffLine { + type: "new" | "old" | "same"; + line: string; + } + export interface IDE { getSerializedConfig(): Promise; getConfigJsUrl(): Promise; @@ -248,6 +255,12 @@ declare global { newContents: string, stepIndex: number ): Promise; + verticalDiffUpdate( + filepath: string, + startLine: number, + endLine: number, + diffLine: DiffLine + ): Promise; getOpenFiles(): Promise; } @@ -411,6 +424,7 @@ declare global { temperature?: number; topP?: number; topK?: number; + minP?: number; presencePenalty?: number; frequencyPenalty?: number; stop?: string[]; @@ -428,6 +442,7 @@ declare global { completionOptions?: BaseCompletionOptions; systemMessage?: string; requestOptions?: RequestOptions; + promptTemplates?: { [key: string]: string }; } export interface ModelRoles { diff --git a/core/index.d.ts b/core/index.d.ts index 994a72d74..4ad1b1e2b 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -440,6 +440,7 @@ export interface ModelDescription { completionOptions?: BaseCompletionOptions; systemMessage?: string; requestOptions?: RequestOptions; + promptTemplates?: { [key: string]: string }; } export interface ModelRoles { diff --git a/core/llm/index.ts b/core/llm/index.ts index b73806478..d3769b9c7 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -197,8 +197,8 @@ export abstract class BaseLLM implements ILLM { }; this.requestOptions = options.requestOptions; this.promptTemplates = { - ...options.promptTemplates, ...autodetectPromptTemplates(options.model, templateType), + ...options.promptTemplates, }; this.templateMessages = options.templateMessages || diff --git a/extensions/vscode/manual-testing-sandbox/example.ts b/extensions/vscode/manual-testing-sandbox/example.ts index ad42c22d0..afb490c6a 100644 --- a/extensions/vscode/manual-testing-sandbox/example.ts +++ b/extensions/vscode/manual-testing-sandbox/example.ts @@ -1,3 +1,32 @@ -function mergeSortAlgorithm() { - // TODO: implement +function mergeSortAlgorithm(arr) { + // If the length of the array is less than or equal to one, return the original array + if (arr.length <= 1) { + return arr; + } + + // Find the middle index of the array + const mid = Math.floor(arr.length / 2); + + // Split the array into two halves: left and right + const left = arr.slice(0, mid); + const right = arr.slice(mid); + + // Recursively sort the left and right arrays + return merge(mergeSortAlgorithm(left), mergeSortAlgorithm(right)); +} + +function merge(left, right) { + let result = []; + let leftIndex = 0; + let rightIndex = 0; + while (leftIndex < left.length && rightIndex < right.length) { + if (left[leftIndex] < right[rightIndex]) { + result.push(left[leftIndex]); + leftIndex++; + } else { + result.push(right[rightIndex]); + rightIndex++; + } + } + return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex)); } diff --git a/extensions/vscode/src/terminal/terminalEmulator.ts b/extensions/vscode/src/terminal/terminalEmulator.ts index 3b90f9f8c..15faf0993 100644 --- a/extensions/vscode/src/terminal/terminalEmulator.ts +++ b/extensions/vscode/src/terminal/terminalEmulator.ts @@ -1,8 +1,8 @@ /* Terminal emulator - commented because node-pty is causing problems. */ -import * as vscode from "vscode"; -import * as os from 'os'; +import * as os from "os"; import stripAnsi from "strip-ansi"; +import * as vscode from "vscode"; import { longestCommonSubsequence } from "../util/lcs"; function loadNativeModule(id: string): T | null { @@ -25,7 +25,7 @@ const pty = loadNativeModule("node-pty"); function getDefaultShell(): string { if (process.platform !== "win32") { - return os.userInfo().shell; + return os.userInfo().shell || "cmd"; } switch (process.platform) { case "win32":