🚧 /edit working

This commit is contained in:
Nate Sesti 2023-12-11 10:33:19 -08:00
parent 7cfdd83b25
commit ffd4e6f046
13 changed files with 382 additions and 258 deletions

View file

@ -47,7 +47,7 @@ Raise an error if the key already exists.
Main task:
`;
async function getPromptParts(
export async function getPromptParts(
rif: RangeInFileWithContents,
fullFileContents: string,
model: LLM,
@ -207,7 +207,7 @@ function lineToBeIgnored(line: string, isFirstLine: boolean = false): boolean {
);
}
function contextItemToRangeInFileWithContents(
export function contextItemToRangeInFileWithContents(
item: ContextItem
): RangeInFileWithContents {
const lines = item.name.split("(")[1].split(")")[0].split("-");
@ -235,12 +235,14 @@ const EditSlashCommand: SlashCommand = {
description: "Edit highlighted code",
run: async function* ({ ide, llm, input, history, contextItems }) {
const contextItemToEdit = contextItems.find(
(item: ContextItem) => item.editing && item.id.providerTitle === "file"
(item: ContextItem) => item.editing && item.id.providerTitle === "code"
);
if (!contextItemToEdit) {
yield "Highlight the code that you want to edit first";
return;
}
const rif: RangeInFileWithContents =
contextItemToRangeInFileWithContents(contextItemToEdit);
@ -431,9 +433,11 @@ const EditSlashCommand: SlashCommand = {
}
let messages = history;
messages.push({ role: "user", content: prompt });
let linesOfPrefixCopied = 0;
let lines = [];
let unfinishedLine = "";
let unfinishedLine: string = "";
let completionLinesCovered = 0;
let repeatingFileSuffix = false;
let lineBelowHighlightedRange = fileSuffix.trim().split("\n")[0];
@ -486,115 +490,93 @@ const EditSlashCommand: SlashCommand = {
generator = gen();
}
for await (const chunk of generator) {
yield chunk;
let lastTaskTime = Date.now();
for await (let chunk of generator) {
// Stop early if it is repeating the fileSuffix or the step was deleted
if (repeatingFileSuffix) {
break;
}
// Accumulate lines
let chunkLines = chunk.split("\n");
chunkLines[0] = unfinishedLine + chunkLines[0];
if (chunk.endsWith("\n")) {
unfinishedLine = "";
chunkLines.pop(); // because this will be an empty string
} else {
unfinishedLine = chunkLines.pop() || "";
}
// Deal with newly accumulated lines
for (let i = 0; i < chunkLines.length; i++) {
// Trailing whitespace doesn't matter
chunkLines[i] = chunkLines[i].trimEnd();
chunkLines[i] = commonWhitespace + chunkLines[i];
// Lines that should signify the end of generation
if (isEndLine(chunkLines[i])) {
break;
}
// Lines that should be ignored, like the <> tags
else if (lineToBeIgnored(chunkLines[i], completionLinesCovered === 0)) {
continue; // noice
}
// Check if we are currently just copying the prefix
else if (
(linesOfPrefixCopied > 0 || completionLinesCovered === 0) &&
linesOfPrefixCopied < filePrefix.split("\n").length &&
chunkLines[i] === fullFileContentsLines[linesOfPrefixCopied]
) {
// This is a sketchy way of stopping it from repeating the filePrefix. Is a bug if output happens to have a matching line
linesOfPrefixCopied += 1;
continue; // also nice
}
// Because really short lines might be expected to be repeated, this is only a !heuristic!
// Stop when it starts copying the fileSuffix
else if (
chunkLines[i].trim() === lineBelowHighlightedRange.trim() &&
chunkLines[i].trim().length > 4 &&
!(
originalLinesBelowPreviousBlocks.length > 0 &&
chunkLines[i].trim() === originalLinesBelowPreviousBlocks[0].trim()
)
) {
repeatingFileSuffix = true;
break;
}
lines.push(chunkLines[i]);
completionLinesCovered += 1;
currentLineInFile += 1;
}
// Debounce the diff updates, last in only out for each period
if (lastTaskTime === null || Date.now() - lastTaskTime > 150) {
lastTaskTime = Date.now();
await sendDiffUpdate(
lines.concat([
unfinishedLine?.startsWith("<")
? commonWhitespace
: commonWhitespace + unfinishedLine,
])
);
}
}
// try {
// let lastTaskTime = Date.now();
// for await (let chunk of generator) {
// yield new SetStep(
// false
// ); // Doing this so that there are breakpoints for cancellation
// Add the unfinished line
if (
unfinishedLine !== "" &&
!lineToBeIgnored(unfinishedLine, completionLinesCovered === 0) &&
!isEndLine(unfinishedLine)
) {
unfinishedLine = commonWhitespace + unfinishedLine;
lines.push(unfinishedLine);
await handleGeneratedLine(unfinishedLine);
completionLinesCovered += 1;
currentLineInFile += 1;
}
// // Stop early if it is repeating the fileSuffix or the step was deleted
// if (repeatingFileSuffix) {
// break;
// }
// // Accumulate lines
// let chunkLines = chunk.split("\n");
// chunkLines[0] = unfinishedLine + chunkLines[0];
// if (chunk.endsWith("\n")) {
// unfinishedLine = "";
// chunkLines.pop(); // because this will be an empty string
// } else {
// unfinishedLine = chunkLines.pop();
// }
// // Deal with newly accumulated lines
// for (let i = 0; i < chunkLines.length; i++) {
// // Trailing whitespace doesn't matter
// chunkLines[i] = chunkLines[i].trimEnd();
// chunkLines[i] = commonWhitespace + chunkLines[i];
// // Lines that should signify the end of generation
// if (this.isEndLine(chunkLines[i])) {
// break;
// }
// // Lines that should be ignored, like the <> tags
// else if (this.lineToBeIgnored(
// chunkLines[i], completionLinesCovered === 0
// )) {
// continue; // noice
// }
// // Check if we are currently just copying the prefix
// else if (
// (linesOfPrefixCopied > 0 || completionLinesCovered === 0)
// && linesOfPrefixCopied < filePrefix.splitlines().length
// && chunkLines[i]
// === fullFileContentsLines[linesOfPrefixCopied]
// ) {
// // This is a sketchy way of stopping it from repeating the filePrefix. Is a bug if output happens to have a matching line
// linesOfPrefixCopied += 1;
// continue; // also nice
// }
// // Because really short lines might be expected to be repeated, this is only a !heuristic!
// // Stop when it starts copying the fileSuffix
// else if (
// chunkLines[i].trim() === lineBelowHighlightedRange.trim()
// && chunkLines[i].trim().length > 4
// && !(
// originalLinesBelowPreviousBlocks.length > 0
// && chunkLines[i].trim()
// === originalLinesBelowPreviousBlocks[0].trim()
// )
// ) {
// repeatingFileSuffix = true;
// break;
// }
// lines.push(chunkLines[i]);
// completionLinesCovered += 1;
// currentLineInFile += 1
// }
// // Debounce the diff updates, last in only out for each period
// if (lastTaskTime === null || Date.now() - lastTaskTime > 150) {
// lastTaskTime = Date.now();
// await sendDiffUpdate(
// lines
// .concat(
// [unfinishedLine.startsWith("<")
// ? commonWhitespace
// : (commonWhitespace + unfinishedLine)]
// ),
// sdk,
// );
// }
// } finally {
// await generator.return();
// }
// // Add the unfinished line
// if (
// unfinishedLine !== ""
// && !this.lineToBeIgnored(
// unfinishedLine, completionLinesCovered === 0
// )
// && !this.isEndLine(unfinishedLine)
// ) {
// unfinishedLine = commonWhitespace + unfinishedLine;
// lines.push(unfinishedLine);
// await handleGeneratedLine(unfinishedLine);
// completionLinesCovered += 1;
// currentLineInFile += 1;
// }
// await sendDiffUpdate(lines, sdk, true);
// },
await sendDiffUpdate(lines, true);
},
};

View file

@ -108,7 +108,7 @@ function autodetectPromptTemplates(
editTemplate = alpacaEditPrompt;
} else if (templateType === "deepseek") {
editTemplate = deepseekEditPrompt;
} else if (templateType !== null) {
} else if (templateType) {
editTemplate = simplestEditPrompt;
}

View file

@ -1,13 +1,57 @@
// import * as dotenv from "dotenv";
// import { ContinueSDK } from "../../commands";
// import EditSlashCommand from "../../commands/slash/edit";
// import EditSlashCommand, {
// contextItemToRangeInFileWithContents,
// getPromptParts,
// } from "../../commands/slash/edit";
// import FileSystemIde from "../../ide/filesystem";
// import { dedentAndGetCommonWhitespace } from "../../util";
// import FreeTrial from "../llms/FreeTrial";
// jest.setTimeout(100_000);
// dotenv.config();
// const TEST_CONTEXT_ITEM = {
// name: "editme.py (1-2)",
// description: "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
// content: "def average(nums: list) -> float:\n pass\n",
// id: {
// providerTitle: "code",
// itemId: "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
// },
// editing: true,
// };
// const f1 = `\
// def maximum(nums: list) -> float:
// return max(nums)
// `;
// const f2 = `\
// def total(nums: list) -> float:
// s = sum(nums)
// return s
// `;
// const f3 = `\
// def average(nums: list) -> float:
// return sum(nums) / len(nums)
// `;
// const fullFile = `${f1}\n${f2}\n${f3}\n`;
// const TEST_CONTEXT_ITEM2 = {
// name: "editme2.py (4-7)",
// description: "/Users/natesesti/Desktop/continue/core/llm/test/editme2.py",
// content: f2,
// id: {
// providerTitle: "code",
// itemId: "/Users/natesesti/Desktop/continue/core/llm/test/editme2.py",
// },
// editing: true,
// };
// describe("/edit slash command", () => {
// test("doesn't break", async () => {
// const command = EditSlashCommand;
@ -17,18 +61,7 @@
// addContextItem: (item: any) => {},
// history: [],
// input: "implement this function",
// contextItems: [
// {
// name: "editme.py (1-2)",
// description:
// "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
// content: "def average(nums: list) -> float:\n pass\n",
// id: {
// providerTitle: "file",
// itemId: "/Users/natesesti/Desktop/continue/core/llm/test/editme.py",
// },
// },
// ],
// contextItems: [TEST_CONTEXT_ITEM],
// options: {},
// };
@ -38,4 +71,48 @@
// }
// console.log(total);
// });
// test.skip("dedentAndGetCommonWhitespace", () => {
// // TODO
// let [dedented, whitespace] = dedentAndGetCommonWhitespace(
// `\
// ...
// ...
// ...
// ..
// . .`
// );
// expect(dedented).toEqual(`\
// ...
// ...
// ...
// ..
// . .`);
// expect(whitespace).toEqual(" ");
// let [dedented2, whitespace2] = dedentAndGetCommonWhitespace("");
// expect(dedented2).toEqual("");
// expect(whitespace2).toEqual("");
// let [dedented3, whitespace3] = dedentAndGetCommonWhitespace(" \n\n ");
// expect(dedented3).toEqual(" \n\n ");
// expect(whitespace3).toEqual("");
// });
// test.skip("getPromptParts", async () => {
// // TODO
// const { filePrefix, fileSuffix, contents, maxTokens } =
// await getPromptParts(
// contextItemToRangeInFileWithContents(TEST_CONTEXT_ITEM2),
// fullFile,
// new FreeTrial({ model: "gpt-3.5-turbo" }),
// "implement this function"
// );
// expect(filePrefix).toEqual(`${f1}`);
// expect(`${fileSuffix}\n`).toEqual(`\n${f3}`);
// expect(contents).toEqual(f2);
// expect(maxTokens).toEqual(2048);
// });
// });

View file

@ -1,96 +1,99 @@
// import * as dotenv from "dotenv";
// import { LLM } from "..";
// import Together from "../llms/Together";
// import { CompletionOptions } from "../types";
// // import * as dotenv from "dotenv";
// // import { LLM } from "..";
// // import Together from "../llms/Together";
// // import { CompletionOptions } from "../types";
// jest.setTimeout(100_000);
// // jest.setTimeout(100_000);
// dotenv.config();
// // dotenv.config();
// const COMPLETION_OPTIONS: Partial<CompletionOptions> = {
// temperature: 0.5,
// topP: 1,
// topK: 40,
// presencePenalty: 0,
// frequencyPenalty: 0,
// // stop: ["\n"],
// // maxTokens: 5,
// };
// // const COMPLETION_OPTIONS: Partial<CompletionOptions> = {
// // temperature: 0.5,
// // topP: 1,
// // topK: 40,
// // presencePenalty: 0,
// // frequencyPenalty: 0,
// // // stop: ["\n"],
// // // maxTokens: 5,
// // };
// function testLLM(llm: LLM) {
// beforeAll(() => {
// llm.completionOptions = { ...llm.completionOptions, ...COMPLETION_OPTIONS };
// });
// // function testLLM(llm: LLM) {
// // beforeAll(() => {
// // llm.completionOptions = { ...llm.completionOptions, ...COMPLETION_OPTIONS };
// // });
// describe(llm.providerName, () => {
// test("Stream Chat works", async () => {
// let total = "";
// for await (const chunk of llm.streamChat([
// { role: "user", content: "Hello" },
// ])) {
// total += chunk.content;
// }
// // describe(llm.providerName, () => {
// // test("Stream Chat works", async () => {
// // let total = "";
// // for await (const chunk of llm.streamChat([
// // { role: "user", content: "Hello" },
// // ])) {
// // total += chunk.content;
// // }
// expect(total.length).toBeGreaterThan(0);
// console.log(total);
// return;
// });
// // expect(total.length).toBeGreaterThan(0);
// // console.log(total);
// // return;
// // });
// test("Stream Complete works", async () => {
// let total = "";
// for await (const chunk of llm.streamComplete("Hello")) {
// total += chunk;
// }
// // test("Stream Complete works", async () => {
// // let total = "";
// // for await (const chunk of llm.streamComplete("Hello")) {
// // total += chunk;
// // }
// expect(total.length).toBeGreaterThan(0);
// console.log(total);
// return;
// });
// // expect(total.length).toBeGreaterThan(0);
// // console.log(total);
// // return;
// // });
// test("Complete works", async () => {
// const completion = await llm.complete("Hello");
// // test("Complete works", async () => {
// // const completion = await llm.complete("Hello");
// expect(completion.length).toBeGreaterThan(0);
// console.log(completion);
// return;
// });
// });
// }
// // expect(completion.length).toBeGreaterThan(0);
// // console.log(completion);
// // return;
// // });
// // });
// // }
// describe("LLM", () => {
// // testLLM(
// // new FreeTrial({
// // model: "gpt-3.5-turbo",
// // })
// // );
// // testLLM(
// // new Anthropic({
// // model: "claude-2",
// // apiKey: process.env.ANTHROPIC_API_KEY,
// // })
// // );
// // testLLM(
// // new OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: "gpt-3.5-turbo" })
// // );
// // TODO: Fix Replicate
// // testLLM(
// // new Replicate({
// // apiKey: process.env.REPLICATE_API_KEY,
// // model: "codellama-7b",
// // })
// // );
// // testLLM(new LMStudio({ model: "codellama-7b" }));
// // testLLM(new Ollama({ model: "codellama-7b" }));
// testLLM(
// new Together({
// apiKey: process.env.TOGETHER_API_KEY,
// model: "codellama-7b",
// })
// );
// // testLLM(new LlamaCpp({ model: "deepseek-7b" }));
// // testLLM(new Llamafile({ model: "mistral-7b" }));
// // TODO: Test these
// // testLLM(new TextGenWebUI({ model: "codellama-7b" }));
// // testLLM(new HuggingFaceTGI({ model: "codellama-7b" }));
// // testLLM(new HuggingFaceInferenceAPI({ model: "codellama-7b" }));
// // // testLLM(
// // // new FreeTrial({
// // // model: "gpt-3.5-turbo",
// // // })
// // // );
// // // testLLM(
// // // new Anthropic({
// // // model: "claude-2",
// // // apiKey: process.env.ANTHROPIC_API_KEY,
// // // })
// // // );
// // // testLLM(
// // // new OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: "gpt-3.5-turbo" })
// // // );
// // // TODO: Fix Replicate
// // // testLLM(
// // // new Replicate({
// // // apiKey: process.env.REPLICATE_API_KEY,
// // // model: "codellama-7b",
// // // })
// // // );
// // // testLLM(new LMStudio({ model: "codellama-7b" }));
// // // testLLM(new Ollama({ model: "codellama-7b" }));
// // testLLM(
// // new Together({
// // apiKey: process.env.TOGETHER_API_KEY,
// // model: "codellama-7b",
// // })
// // );
// // // testLLM(new LlamaCpp({ model: "deepseek-7b" }));
// // // testLLM(new Llamafile({ model: "mistral-7b" }));
// // // TODO: Test these
// // // testLLM(new TextGenWebUI({ model: "codellama-7b" }));
// // // testLLM(new HuggingFaceTGI({ model: "codellama-7b" }));
// // // testLLM(new HuggingFaceInferenceAPI({ model: "codellama-7b" }));
// test.skip("works", () => {
// expect(true).toBe(true);
// });
// });

72
core/package-lock.json generated
View file

@ -11,13 +11,14 @@
"license": "Apache-2.0",
"dependencies": {
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
@ -1144,6 +1145,16 @@
"@types/node": "*"
}
},
"node_modules/@types/handlebars": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@types/handlebars/-/handlebars-4.1.0.tgz",
"integrity": "sha512-gq9YweFKNNB1uFK71eRqsd4niVkXrxHugqWFQkeLRJvGjnxsLr16bYtcsG4tOFwmYi0Bax+wCkbf1reUfdl4kA==",
"deprecated": "This is a stub types definition. handlebars provides its own type definitions, so you do not need this installed.",
"dev": true,
"dependencies": {
"handlebars": "*"
}
},
"node_modules/@types/istanbul-lib-coverage": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
@ -2188,6 +2199,26 @@
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true
},
"node_modules/handlebars": {
"version": "4.7.8",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
"integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
"dependencies": {
"minimist": "^1.2.5",
"neo-async": "^2.6.2",
"source-map": "^0.6.1",
"wordwrap": "^1.0.0"
},
"bin": {
"handlebars": "bin/handlebars"
},
"engines": {
"node": ">=0.4.7"
},
"optionalDependencies": {
"uglify-js": "^3.1.4"
}
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
@ -3271,25 +3302,30 @@
"node": "*"
}
},
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
"bin": {
"mustache": "bin/mustache"
}
},
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
"dev": true
},
"node_modules/neo-async": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
@ -3735,7 +3771,6 @@
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
@ -4063,6 +4098,18 @@
"node": ">=14.17"
}
},
"node_modules/uglify-js": {
"version": "3.17.4",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
"integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
"optional": true,
"bin": {
"uglifyjs": "bin/uglifyjs"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
@ -4178,6 +4225,11 @@
"node": ">= 8"
}
},
"node_modules/wordwrap": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
"integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q=="
},
"node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",

View file

@ -14,17 +14,18 @@
"author": "Nate Sesti and Ty Dunn",
"license": "Apache-2.0",
"devDependencies": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
"cargo-cp-artifact": "^0.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"cargo-cp-artifact": "^0.1"
"ts-jest": "^29.1.1"
},
"dependencies": {
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"uuid": "^9.0.1"

View file

@ -10,27 +10,26 @@ mod utils;
use neon::prelude::*;
fn sync_results(mut cx: FunctionContext) -> JsResult<JsArray> {
let dir = cx.argument::<JsString>(0)?;
let branch = cx.argument::<JsString>(1)?;
// fn sync_results(mut cx: FunctionContext) -> JsResult<JsArray> {
// let dir = cx.argument::<JsString>(0)?;
// let branch = cx.argument::<JsString>(1)?;
let results = sync::sync(Path::new(&dir), Some(&branch))
// let results = sync::sync(Path::new(&dir), Some(&branch))
let js_array = JsArray::new(&mut cx, 4);
// let js_array = JsArray::new(&mut cx, 4);
for (i, result) in results.iter().enumerate() {
let js_object = JsObject::new(&mut cx);
js_object.set(&mut cx, "name", JsString::new(&mut cx, &result.0))?;
js_object.set(&mut cx, "status", JsString::new(&mut cx, &result.1))?;
js_array.set(&mut cx, i as u32, js_object)?;
}
// for (i, result) in results.iter().enumerate() {
// let js_object = JsObject::new(&mut cx);
// js_object.set(&mut cx, "name", JsString::new(&mut cx, &result.0))?;
// js_object.set(&mut cx, "status", JsString::new(&mut cx, &result.1))?;
// js_array.set(&mut cx, i as u32, js_object)?;
// }
Ok(js_array)
}
// Ok(js_array)
// }
#[neon::main]
fn main(mut cx: ModuleContext) -> NeonResult<()> {
cx.export_function("get", get_num_cpus)?;
Ok(())
}
// #[neon::main]
// fn main(mut cx: ModuleContext) -> NeonResult<()> {
// cx.export_function("get", get_num_cpus)?;
// Ok(())
// }

View file

@ -1,4 +1,4 @@
import Mustache from "mustache";
import Handlebars from "handlebars";
import { ChatMessage } from "../llm/types";
export function removeQuotesAndEscapes(output: string): string {
@ -42,7 +42,7 @@ export function proxyFetch(url: string, init?: RequestInit): Promise<Response> {
export function dedentAndGetCommonWhitespace(s: string): [string, string] {
let lines = s.split("\n");
if (lines.length === 0) {
if (lines.length === 0 || (lines[0].trim() === "" && lines.length === 1)) {
return ["", ""];
}
@ -91,7 +91,8 @@ export function renderPromptTemplate(
data["system_message"] = history.shift()!.content;
}
return Mustache.render(template, data);
const compiledTemplate = Handlebars.compile(template);
return compiledTemplate(data);
} else {
return template(history, otherData);
}

View file

@ -71,19 +71,22 @@
},
"../../core": {
"version": "1.0.0",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
"cargo-cp-artifact": "^0.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
}
@ -11768,13 +11771,15 @@
"core": {
"version": "file:../../core",
"requires": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
"cargo-cp-artifact": "^0.1",
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"jest": "^29.7.0",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"ts-jest": "^29.1.1",

View file

@ -311,7 +311,6 @@
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"tsc": "tsc -p ./",
"tsc-watch": "tsc -watch -p ./",
"typegen": "node scripts/typegen.js",
"rebuild": "electron-rebuild -v 19.1.8 node-pty",
"lint": "eslint src --ext ts",
"build-test": "tsc && node esbuild.test.mjs",

View file

@ -1449,8 +1449,8 @@ core-util-is@1.0.2:
resolved "file:../../core"
dependencies:
dotenv "^16.3.1"
handlebars "^4.7.8"
js-tiktoken "^1.0.8"
mustache "^4.2.0"
openai "^4.20.1"
replicate "^0.23.0"
uuid "^9.0.1"

9
gui/package-lock.json generated
View file

@ -57,19 +57,22 @@
},
"../core": {
"version": "1.0.0",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
"cargo-cp-artifact": "^0.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
}
@ -6449,13 +6452,15 @@
"core": {
"version": "file:../core",
"requires": {
"@types/handlebars": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/mustache": "^4.2.5",
"@types/uuid": "^9.0.7",
"cargo-cp-artifact": "^0.1",
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"jest": "^29.7.0",
"js-tiktoken": "^1.0.8",
"mustache": "^4.2.0",
"openai": "^4.20.1",
"replicate": "^0.23.0",
"ts-jest": "^29.1.1",

View file

@ -90,16 +90,6 @@ function useChatHandler(dispatch: Dispatch) {
}
async function streamResponse(input: string, index?: number) {
posthog.capture("step run", {
step_name: "User Input",
params: {
user_input: input,
},
});
posthog.capture("userInput", {
input,
});
const message: ChatMessage = {
role: "user",
content: input,
@ -118,6 +108,16 @@ function useChatHandler(dispatch: Dispatch) {
dispatch(submitMessage(message));
}
posthog.capture("step run", {
step_name: "User Input",
params: {
user_input: input,
},
});
posthog.capture("userInput", {
input,
});
const messages = constructMessages(newHistory);
// Determine if the input is a slash command