From 9547a5a82ed81dc9a881a1fc3df397fa56dbf60a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 5 Jan 2024 11:23:13 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20xwin-coder=20prompt=20templat?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.d.ts | 3 ++- core/llm/index.ts | 9 +++++++++ core/llm/templates/chat.ts | 29 ++++++++++++++++++++++++++++ core/llm/templates/edit.ts | 11 +++++++++++ extensions/vscode/config_schema.json | 3 ++- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index ef240c99c..f7389260b 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -320,7 +320,8 @@ type TemplateType = | "chatml" | "none" | "openchat" - | "deepseek"; + | "deepseek" + | "xwin-coder"; type ModelProvider = | "openai" diff --git a/core/llm/index.ts b/core/llm/index.ts index 9c8d847cc..458529af3 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -24,6 +24,7 @@ import { openchatTemplateMessages, phindTemplateMessages, templateAlpacaMessages, + xWinCoderTemplateMessages, zephyrTemplateMessages, } from "./templates/chat"; import { @@ -34,6 +35,7 @@ import { openchatEditPrompt, phindEditPrompt, simplestEditPrompt, + xWinCoderEditPrompt, zephyrEditPrompt, } from "./templates/edit"; @@ -58,6 +60,10 @@ function autodetectTemplateType( return undefined; } + if (lower.includes("xwin")) { + return "xwin-coder"; + } + if (lower.includes("dolphin")) { return "chatml"; } @@ -115,6 +121,7 @@ function autodetectTemplateFunction( chatml: chatmlTemplateMessages, deepseek: deepseekTemplateMessages, openchat: openchatTemplateMessages, + "xwin-coder": xWinCoderTemplateMessages, none: null, }; @@ -151,6 +158,8 @@ function autodetectPromptTemplates( editTemplate = deepseekEditPrompt; } else if (templateType === "openchat") { editTemplate = openchatEditPrompt; + } else if (templateType === "xwin-coder") { + editTemplate = xWinCoderEditPrompt; } else if (templateType) { editTemplate = simplestEditPrompt; } diff --git a/core/llm/templates/chat.ts b/core/llm/templates/chat.ts index 1bc3f1848..b32072f0b 100644 --- a/core/llm/templates/chat.ts +++ b/core/llm/templates/chat.ts @@ -177,6 +177,34 @@ function openchatTemplateMessages(msgs: ChatMessage[]): string { return prompt; } +/** + * Chat template used by https://huggingface.co/TheBloke/XwinCoder-13B-GPTQ + * + +: You are an AI coding assistant that helps people with programming. Write a response that appropriately completes the user's request. +: {prompt} +: + */ +function xWinCoderTemplateMessages(msgs: ChatMessage[]): string { + let prompt = ": "; + if (msgs[0].role === "system") { + prompt += msgs.shift()!.content; + } else { + prompt += + "You are an AI coding assistant that helps people with programming. Write a response that appropriately completes the user's request."; + } + + for (let msg of msgs) { + prompt += "\n"; + prompt += msg.role === "user" ? "" : ""; + prompt += ": " + msg.content; + } + + prompt += ": "; + + return prompt; +} + export { anthropicTemplateMessages, chatmlTemplateMessages, @@ -185,5 +213,6 @@ export { openchatTemplateMessages, phindTemplateMessages, templateAlpacaMessages, + xWinCoderTemplateMessages, zephyrTemplateMessages, }; diff --git a/core/llm/templates/edit.ts b/core/llm/templates/edit.ts index 17160ed06..89ed2ea29 100644 --- a/core/llm/templates/edit.ts +++ b/core/llm/templates/edit.ts @@ -114,6 +114,16 @@ Please only respond with code and put it inside of a markdown code block. Do not \`\`\`{{{language}}} `; +const xWinCoderEditPrompt = `: You are an AI coding assistant that helps people with programming. Write a response that appropriately completes the user's request. +: Please rewrite the following code with these instructions: "{{{userInput}}}" +\`\`\`{{{language}}} +{{{codeToEdit}}} +\`\`\` + +Just rewrite the code without explanations: +: +\`\`\`{{{language}}}`; + export { alpacaEditPrompt, codellamaEditPrompt, @@ -125,5 +135,6 @@ export { phindEditPrompt, simplestEditPrompt, simplifiedEditPrompt, + xWinCoderEditPrompt, zephyrEditPrompt, }; diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index dcbecb875..014639790 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -145,7 +145,8 @@ "chatml", "none", "deepseek", - "openchat" + "openchat", + "xwin-coder" ], "type": "string" },