Elffuss BraidHub

kikocis/continue public

main · 7.9 KiBRawPermalink
1import { ChatMessage, PromptTemplate } from "../../index.js";
2import { gptEditPrompt } from "./edit/gpt.js";
3
4const simplifiedEditPrompt = `Consider the following code:
5\`\`\`{{{language}}}
6{{{codeToEdit}}}
7\`\`\`
8Edit the code to perfectly satisfy the following user request:
9{{{userInput}}}
10Output nothing except for the code. No code block, no English explanation, no start/end tags.`;
11
12const simplestEditPrompt = `Here is the code before editing:
13\`\`\`{{{language}}}
14{{{codeToEdit}}}
15\`\`\`
16
17Here is the edit requested:
18"{{{userInput}}}"
19
20Here is the code after editing:`;
21
22const codellamaInfillEditPrompt = "{{filePrefix}}<FILL>{{fileSuffix}}";
23
24const START_TAG = "<START EDITING HERE>";
25const osModelsEditPrompt: PromptTemplate = (history, otherData) => {
26 // "No sufix" means either there is no suffix OR
27 // it's a clean break at end of function or something
28 // (what we're trying to avoid is just the language model trying to complete the closing brackets of a function or something)
29 const firstCharOfFirstLine = otherData.suffix?.split("\n")[0]?.[0]?.trim();
30 const isSuffix =
31 otherData.suffix?.trim() !== "" &&
32 // First character of first line is whitespace
33 // Otherwise we assume it's a clean break
34 !firstCharOfFirstLine;
35 const suffixTag = isSuffix ? "<STOP EDITING HERE>" : "";
36 const suffixExplanation = isSuffix
37 ? ' When you get to "<STOP EDITING HERE>", end your response.'
38 : "";
39
40 // If neither prefilling nor /v1/completions are supported, we have to use a chat prompt without putting words in the model's mouth
41 if (
42 otherData.supportsCompletions !== "true" &&
43 otherData.supportsPrefill !== "true"
44 ) {
45 return gptEditPrompt(history, otherData);
46 }
47
48 // Use a different prompt when there's neither prefix nor suffix
49 if (otherData.prefix?.trim() === "" && otherData.suffix?.trim() === "") {
50 return [
51 {
52 role: "user",
53 content: `\`\`\`${otherData.language}
54${otherData.codeToEdit}
55${suffixTag}
56\`\`\`
57
58Please rewrite the entire code block above in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before.${suffixExplanation}`,
59 },
60 {
61 role: "assistant",
62 content: `Sure! Here's the entire rewritten code block:
63\`\`\`${otherData.language}
64`,
65 },
66 ];
67 }
68
69 return [
70 {
71 role: "user",
72 content: `\`\`\`${otherData.language}
73${otherData.prefix}${START_TAG}
74${otherData.codeToEdit}
75${suffixTag}
76\`\`\`
77
78Please rewrite the entire code block above, editing the portion below "${START_TAG}" in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before.${suffixExplanation}
79`,
80 },
81 {
82 role: "assistant",
83 content: `Sure! Here's the entire code block, including the rewritten portion:
84\`\`\`${otherData.language}
85${otherData.prefix}${START_TAG}
86`,
87 },
88 ];
89};
90
91const mistralEditPrompt = `[INST] You are a helpful code assistant. Your task is to rewrite the following code with these instructions: "{{{userInput}}}"
92\`\`\`{{{language}}}
93{{{codeToEdit}}}
94\`\`\`
95
96Just rewrite the code without explanations: [/INST]
97\`\`\`{{{language}}}`;
98
99const alpacaEditPrompt = `Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
100
101### Instruction: Rewrite the code to satisfy this request: "{{{userInput}}}"
102
103### Input:
104
105\`\`\`{{{language}}}
106{{{codeToEdit}}}
107\`\`\`
108
109### Response:
110
111Sure! Here's the code you requested:
112\`\`\`{{{language}}}
113`;
114
115const phindEditPrompt = `### System Prompt
116You are an expert programmer and write code on the first attempt without any errors or fillers.
117
118### User Message:
119Rewrite the code to satisfy this request: "{{{userInput}}}"
120
121\`\`\`{{{language}}}
122{{{codeToEdit}}}
123\`\`\`
124
125### Assistant:
126Sure! Here's the code you requested:
127
128\`\`\`{{{language}}}
129`;
130
131const deepseekEditPrompt = `### System Prompt
132You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and your role is to assist with questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will not answer.
133### Instruction:
134Rewrite the code to satisfy this request: "{{{userInput}}}"
135
136\`\`\`{{{language}}}
137{{{codeToEdit}}}
138\`\`\`<|EOT|>
139### Response:
140Sure! Here's the code you requested:
141
142\`\`\`{{{language}}}
143`;
144
145const zephyrEditPrompt = `<|system|>
146You are an expert programmer and write code on the first attempt without any errors or fillers.</s>
147<|user|>
148Rewrite the code to satisfy this request: "{{{userInput}}}"
149
150\`\`\`{{{language}}}
151{{{codeToEdit}}}
152\`\`\`</s>
153<|assistant|>
154Sure! Here's the code you requested:
155
156\`\`\`{{{language}}}
157`;
158
159const openchatEditPrompt = `GPT4 Correct User: You are an expert programmer and personal assistant. You are asked to rewrite the following code in order to {{{userInput}}}.
160\`\`\`{{{language}}}
161{{{codeToEdit}}}
162\`\`\`
163Please only respond with code and put it inside of a markdown code block. Do not give any explanation, but your code should perfectly satisfy the user request.<|end_of_turn|>GPT4 Correct Assistant: Sure thing! Here is the rewritten code that you requested:
164\`\`\`{{{language}}}
165`;
166
167const xWinCoderEditPrompt = `<system>: You are an AI coding agent that helps people with programming. Write a response that appropriately completes the user's request.
168<user>: Please rewrite the following code with these instructions: "{{{userInput}}}"
169\`\`\`{{{language}}}
170{{{codeToEdit}}}
171\`\`\`
172
173Just rewrite the code without explanations:
174<AI>:
175\`\`\`{{{language}}}`;
176
177const neuralChatEditPrompt = `### System:
178You are an expert programmer and write code on the first attempt without any errors or fillers.
179### User:
180Rewrite the code to satisfy this request: "{{{userInput}}}"
181
182\`\`\`{{{language}}}
183{{{codeToEdit}}}
184\`\`\`
185### Assistant:
186Sure! Here's the code you requested:
187
188\`\`\`{{{language}}}
189`;
190
191const codeLlama70bEditPrompt = `<s>Source: system\n\n You are an expert programmer and write code on the first attempt without any errors or fillers. <step> Source: user\n\n Rewrite the code to satisfy this request: "{{{userInput}}}"
192
193\`\`\`{{{language}}}
194{{{codeToEdit}}}
195\`\`\` <step> Source: assistant\nDestination: user\n\n `;
196
197const claudeEditPrompt: PromptTemplate = (
198 history: ChatMessage[],
199 otherData: Record<string, string>,
200) => [
201 {
202 role: "user",
203 content: `\
204\`\`\`${otherData.language}
205${otherData.codeToEdit}
206\`\`\`
207
208You are an expert programmer. You will rewrite the above code to do the following:
209
210${otherData.userInput}
211
212Output only a code block with the rewritten code:
213`,
214 },
215 {
216 role: "assistant",
217 content: `Sure! Here is the rewritten code:
218\`\`\`${otherData.language}`,
219 },
220];
221
222const llama3EditPrompt: PromptTemplate = `<|begin_of_text|><|start_header_id|>user<|end_header_id|>
223\`\`\`{{{language}}}
224{{{codeToEdit}}}
225\`\`\`
226
227Rewrite the above code to satisfy this request: "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
228Sure! Here's the code you requested:
229\`\`\`{{{language}}}`;
230
231const gemmaEditPrompt = `<start_of_turn>user
232You are an expert programmer and write code on the first attempt without any errors or fillers. Rewrite the code to satisfy this request: "{{{userInput}}}"
233
234\`\`\`{{{language}}}
235{{{codeToEdit}}}
236\`\`\`<end_of_turn>
237<start_of_turn>model
238Sure! Here's the code you requested:
239
240\`\`\`{{{language}}}
241`;
242
243export {
244 alpacaEditPrompt,
245 claudeEditPrompt,
246 codeLlama70bEditPrompt,
247 codellamaInfillEditPrompt,
248 deepseekEditPrompt,
249 gemmaEditPrompt,
250 gptEditPrompt,
251 llama3EditPrompt,
252 mistralEditPrompt,
253 neuralChatEditPrompt,
254 openchatEditPrompt,
255 osModelsEditPrompt,
256 phindEditPrompt,
257 simplestEditPrompt,
258 simplifiedEditPrompt,
259 xWinCoderEditPrompt,
260 zephyrEditPrompt,
261};