Elffuss BraidHub

kikocis/continue public

main · 2.7 KiBRawPermalink
1import { PromptTemplateFunction } from "../../..";
2import { dedent } from "../../../util";
3
4const gptInsertionEditPrompt: PromptTemplateFunction = (_, otherData) => {
5 return dedent`
6 \`\`\`${otherData.language}
7 ${otherData.prefix}[BLANK]${otherData.codeToEdit}${otherData.suffix}
8 \`\`\`
9
10 Above is the file of code that the user is currently editing in. Their cursor is located at the "[BLANK]". They have requested that you fill in the "[BLANK]" with code that satisfies the following request:
11
12 "${otherData.userInput}"
13
14 Please generate this code. Your output will be only the code that should replace the "[BLANK]", without repeating any of the prefix or suffix, without any natural language explanation, and without messing up indentation. Here is the code that will replace the "[BLANK]":`;
15};
16
17const gptFullFileEditPrompt: PromptTemplateFunction = (_, otherData) => {
18 return dedent`
19 \`\`\`${otherData.language}
20 ${otherData.codeToEdit}
21 \`\`\`
22
23 Please rewrite the above file to address the following request:
24
25 ${otherData.userInput}
26
27 You should rewrite the entire file without any natural language explanation. DO NOT surround the code in a code block and DO NOT explain yourself.`;
28};
29
30export const gptEditPrompt: PromptTemplateFunction = (history, otherData) => {
31 if (otherData?.codeToEdit?.trim().length === 0) {
32 return gptInsertionEditPrompt(history, otherData);
33 } else if (
34 otherData?.prefix?.trim().length === 0 &&
35 otherData?.suffix?.trim().length === 0
36 ) {
37 return gptFullFileEditPrompt(history, otherData);
38 }
39
40 const paragraphs = [
41 "The user has requested a section of code in a file to be rewritten.",
42 ];
43
44 if (otherData.prefix?.trim().length > 0) {
45 paragraphs.push(dedent`
46 This is the prefix of the file:
47 \`\`\`${otherData.language}
48 ${otherData.prefix}
49 \`\`\``);
50 }
51
52 if (otherData.suffix?.trim().length > 0) {
53 paragraphs.push(dedent`
54 This is the suffix of the file:
55 \`\`\`${otherData.language}
56 ${otherData.suffix}
57 \`\`\``);
58 }
59
60 paragraphs.push(dedent`
61 This is the code to rewrite:
62 \`\`\`${otherData.language}
63 ${otherData.codeToEdit}
64 \`\`\`
65
66 The user's request is: "${otherData.userInput}"
67
68 DO NOT output any natural language, only output the code changes.
69
70 Here is the rewritten code:`);
71
72 return paragraphs.join("\n\n");
73};
74
75export const defaultApplyPrompt: PromptTemplateFunction = (
76 history,
77 otherData,
78) => {
79 return `${otherData.original_code}\n\nThe following code was suggested as an edit:\n\`\`\`\n${otherData.new_code}\n\`\`\`\nPlease apply it to the previous code.`;
80};