From 5164676197ae73b211005c1d20c4a4e97a5d6cde Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 15 Mar 2024 09:57:50 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20gemma=20chat=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.d.ts | 3 ++- core/llm/autodetect.ts | 9 +++++++++ core/llm/templates/chat.ts | 19 +++++++++++++++++++ core/llm/templates/edit.ts | 14 ++++++++++++++ docs/static/schemas/config.json | 5 ++++- .../src/main/resources/config_schema.json | 5 ++++- extensions/vscode/config_schema.json | 5 ++++- extensions/vscode/continue_rc_schema.json | 5 ++++- 8 files changed, 60 insertions(+), 5 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 18f88a2cd..abb337154 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -444,7 +444,8 @@ type TemplateType = | "xwin-coder" | "neural-chat" | "codellama-70b" - | "llava"; + | "llava" + | "gemma"; type ModelProvider = | "openai" diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index c4821aed8..a29ababf8 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -4,6 +4,7 @@ import { chatmlTemplateMessages, codeLlama70bTemplateMessages, deepseekTemplateMessages, + gemmaTemplateMessage, llama2TemplateMessages, llavaTemplateMessages, neuralChatTemplateMessages, @@ -20,6 +21,7 @@ import { codeLlama70bEditPrompt, codellamaEditPrompt, deepseekEditPrompt, + gemmaEditPrompt, mistralEditPrompt, neuralChatEditPrompt, openchatEditPrompt, @@ -129,6 +131,10 @@ function autodetectTemplateType(model: string): TemplateType | undefined { return "chatml"; } + if (lower.includes("gemma")) { + return "gemma"; + } + if (lower.includes("phi2")) { return "phi2"; } @@ -201,6 +207,7 @@ function autodetectTemplateFunction( "neural-chat": neuralChatTemplateMessages, llava: llavaTemplateMessages, "codellama-70b": codeLlama70bTemplateMessages, + gemma: gemmaTemplateMessage, none: null, }; @@ -245,6 +252,8 @@ function autodetectPromptTemplates( editTemplate = codeLlama70bEditPrompt; } else if (templateType === "anthropic") { editTemplate = claudeEditPrompt; + } else if (templateType === "gemma") { + editTemplate = gemmaEditPrompt; } else if (templateType) { editTemplate = simplestEditPrompt; } diff --git a/core/llm/templates/chat.ts b/core/llm/templates/chat.ts index 67d5a04f5..8f004abb8 100644 --- a/core/llm/templates/chat.ts +++ b/core/llm/templates/chat.ts @@ -287,11 +287,30 @@ function codeLlama70bTemplateMessages(msgs: ChatMessage[]): string { return prompt; } +/** + user + What is Cramer's Rule? + model + */ + +function gemmaTemplateMessage(msgs: ChatMessage[]): string { + let prompt = ""; + for (const msg of msgs) { + prompt += `${ + msg.role === "assistant" ? "model" : "user" + }\n${stripImages(msg.content).trim()}\n`; + } + + prompt += "model\n"; + return prompt; +} + export { anthropicTemplateMessages, chatmlTemplateMessages, codeLlama70bTemplateMessages, deepseekTemplateMessages, + gemmaTemplateMessage, llama2TemplateMessages, llavaTemplateMessages, neuralChatTemplateMessages, diff --git a/core/llm/templates/edit.ts b/core/llm/templates/edit.ts index e6383fa21..abe914f74 100644 --- a/core/llm/templates/edit.ts +++ b/core/llm/templates/edit.ts @@ -171,6 +171,19 @@ Output only a code block with the rewritten code: \`\`\`${otherData.language}`, }, ]; + +const gemmaEditPrompt = `user +You are an expert programmer and write code on the first attempt without any errors or fillers. Rewrite the code to satisfy this request: "{{{userInput}}}" + +\`\`\`{{{language}}} +{{{codeToEdit}}} +\`\`\` +model +Sure! Here's the code you requested: + +\`\`\`{{{language}}} +`; + export { alpacaEditPrompt, claudeEditPrompt, @@ -178,6 +191,7 @@ export { codellamaEditPrompt, codellamaInfillEditPrompt, deepseekEditPrompt, + gemmaEditPrompt, gptEditPrompt, mistralEditPrompt, neuralChatEditPrompt, diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 7734d7cef..14fa444e1 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -187,6 +187,7 @@ "llama2", "alpaca", "zephyr", + "phi2", "phind", "anthropic", "chatml", @@ -195,7 +196,9 @@ "openchat", "xwin-coder", "neural-chat", - "codellama-70b" + "codellama-70b", + "llava", + "gemma" ], "type": "string" }, diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 7734d7cef..14fa444e1 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -187,6 +187,7 @@ "llama2", "alpaca", "zephyr", + "phi2", "phind", "anthropic", "chatml", @@ -195,7 +196,9 @@ "openchat", "xwin-coder", "neural-chat", - "codellama-70b" + "codellama-70b", + "llava", + "gemma" ], "type": "string" }, diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 7734d7cef..14fa444e1 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -187,6 +187,7 @@ "llama2", "alpaca", "zephyr", + "phi2", "phind", "anthropic", "chatml", @@ -195,7 +196,9 @@ "openchat", "xwin-coder", "neural-chat", - "codellama-70b" + "codellama-70b", + "llava", + "gemma" ], "type": "string" }, diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 996045153..e21a1c0fb 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -187,6 +187,7 @@ "llama2", "alpaca", "zephyr", + "phi2", "phind", "anthropic", "chatml", @@ -195,7 +196,9 @@ "openchat", "xwin-coder", "neural-chat", - "codellama-70b" + "codellama-70b", + "llava", + "gemma" ], "type": "string" },