@@ -5,8 +5,13 @@ package functorcoder.llm
55 * for completion, code generation, etc.
66 */
77object llmPrompt {
8+ // trait will have undefined value
9+ sealed abstract class Prompt (val assistantMsg : String ) {
10+ def generatePrompt : String
11+ def getAssistantMessage : String = assistantMsg
12+ }
813
9- /** a configuration for code completion
14+ /** code completion prompt
1015 *
1116 * https://github.com/continuedev/continue/blob/main/core/autocomplete/templating/AutocompleteTemplate.ts
1217 *
@@ -26,8 +31,8 @@ object llmPrompt {
2631 case class Completion (
2732 codeWithHole : String , // code with a hole to fill like {{FILL_HERE}}
2833 // taskRequirement: String, // like "Fill the {{FILL_HERE}} hole."
29- assistantMessage : String = prompts .prompt1
30- ) {
34+ assistantMessage : String = promptText .prompt1
35+ ) extends Prompt (assistantMessage) {
3136 def generatePrompt = {
3237 // shall return a string wrapped with <COMPLETION></COMPLETION>
3338 // s"""<QUERY>
@@ -40,13 +45,38 @@ object llmPrompt {
4045 */
4146 codeWithHole
4247 }
48+
49+ }
50+
51+ /** modify code snippet
52+ *
53+ * @param code
54+ * code snippet
55+ * @param taskRequirement
56+ * like "Fill the {{FILL_HERE}} hole."
57+ * @param assistantMessage
58+ * like "always give scala code examples."
59+ */
60+ case class Modification (
61+ code : String ,
62+ taskRequirement : String ,
63+ assistantMessage : String = promptText.promptTask
64+ ) extends Prompt (assistantMessage) {
65+ def generatePrompt = {
66+ s """ <QUERY>
67+ | ${code}
68+ |</QUERY>
69+ |TASK: ${taskRequirement}
70+ | """ .stripMargin
71+ }
4372 }
4473
4574 /** prompts engineering
4675 *
4776 * more like art than science. just try different prompts and see what works best
4877 */
49- object prompts {
78+ object promptText {
79+ val hole = " {{FILL_HERE}}"
5080 val prompt1 =
5181 " You are a code or text autocompletion assistant. " +
5282 " In the provided input, missing code or text are marked as '{{FILL_HERE}}'. " +
@@ -58,11 +88,15 @@ object llmPrompt {
5888 " {{FILL_HERE}} in the string, " +
5989 " your task is to replace this hole with your reply." +
6090 " you only return the string for the hole with indentation, without any quotes"
91+
92+ val promptTask =
93+ " You are given a text or code snippet wrapped in a <QUERY> tag and a TASK requirement. " +
94+ " You are going to return the new snippet according to the TASK requirement. "
6195 }
6296}
6397
6498/* example:
65- <QUERY>
99+ <QUERY>
66100function sum_evens(lim) {
67101 var sum = 0;
68102 for (var i = 0; i < lim; ++i) {
0 commit comments