| 1 | import { PromptTemplateFunction } from "../../.."; |
| 2 | import { dedent } from "../../../util"; |
| 3 | |
| 4 | const codestralInsertionEditPrompt: 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 | |
| 17 | const codestralFullFileEditPrompt: 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 | |
| 30 | export const codestralEditPrompt: PromptTemplateFunction = ( |
| 31 | history, |
| 32 | otherData, |
| 33 | ) => { |
| 34 | if (otherData?.codeToEdit?.trim().length === 0) { |
| 35 | return codestralInsertionEditPrompt(history, otherData); |
| 36 | } else if ( |
| 37 | otherData?.prefix?.trim().length === 0 && |
| 38 | otherData?.suffix?.trim().length === 0 |
| 39 | ) { |
| 40 | return codestralFullFileEditPrompt(history, otherData); |
| 41 | } |
| 42 | |
| 43 | const paragraphs = [ |
| 44 | "The user has requested a section of code in a file to be rewritten.", |
| 45 | ]; |
| 46 | |
| 47 | if (otherData.prefix?.trim().length > 0) { |
| 48 | paragraphs.push(dedent` |
| 49 | This is the prefix of the file: |
| 50 | \`\`\`${otherData.language} |
| 51 | ${otherData.prefix} |
| 52 | \`\`\``); |
| 53 | } |
| 54 | |
| 55 | if (otherData.suffix?.trim().length > 0) { |
| 56 | paragraphs.push(dedent` |
| 57 | This is the suffix of the file: |
| 58 | \`\`\`${otherData.language} |
| 59 | ${otherData.suffix} |
| 60 | \`\`\``); |
| 61 | } |
| 62 | |
| 63 | paragraphs.push(dedent` |
| 64 | This is the "code to rewrite": |
| 65 | \`\`\`${otherData.language} |
| 66 | ${otherData.codeToEdit} |
| 67 | \`\`\` |
| 68 | |
| 69 | The user's request is: "${otherData.userInput}" |
| 70 | |
| 71 | Here is the new version of "code to rewrite". Make sure not to rewrite any of the prefix or suffix:`); |
| 72 | |
| 73 | return paragraphs.join("\n\n"); |
| 74 | }; |