✨ gemma chat template

This commit is contained in:
Nate Sesti 2024-03-15 09:57:50 -07:00
parent e49a3fa584
commit 5164676197
8 changed files with 60 additions and 5 deletions

3
core/index.d.ts vendored
View file

@ -444,7 +444,8 @@ type TemplateType =
| "xwin-coder"
| "neural-chat"
| "codellama-70b"
| "llava";
| "llava"
| "gemma";
type ModelProvider =
| "openai"

View file

@ -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;
}

View file

@ -287,11 +287,30 @@ function codeLlama70bTemplateMessages(msgs: ChatMessage[]): string {
return prompt;
}
/**
<start_of_turn>user
What is Cramer's Rule?<end_of_turn>
<start_of_turn>model
*/
function gemmaTemplateMessage(msgs: ChatMessage[]): string {
let prompt = "";
for (const msg of msgs) {
prompt += `<start_of_turn>${
msg.role === "assistant" ? "model" : "user"
}\n${stripImages(msg.content).trim()}<end_of_turn>\n`;
}
prompt += "<start_of_turn>model\n";
return prompt;
}
export {
anthropicTemplateMessages,
chatmlTemplateMessages,
codeLlama70bTemplateMessages,
deepseekTemplateMessages,
gemmaTemplateMessage,
llama2TemplateMessages,
llavaTemplateMessages,
neuralChatTemplateMessages,

View file

@ -171,6 +171,19 @@ Output only a code block with the rewritten code:
\`\`\`${otherData.language}`,
},
];
const gemmaEditPrompt = `<start_of_turn>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}}}
\`\`\`<end_of_turn>
<start_of_turn>model
Sure! Here's the code you requested:
\`\`\`{{{language}}}
`;
export {
alpacaEditPrompt,
claudeEditPrompt,
@ -178,6 +191,7 @@ export {
codellamaEditPrompt,
codellamaInfillEditPrompt,
deepseekEditPrompt,
gemmaEditPrompt,
gptEditPrompt,
mistralEditPrompt,
neuralChatEditPrompt,

View file

@ -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"
},

View file

@ -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"
},

View file

@ -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"
},

View file

@ -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"
},