✨ llama3 prompt template

This commit is contained in:
Nate Sesti 2024-05-02 13:38:13 -07:00
parent 1b30b9e312
commit 6492263fb5
8 changed files with 39 additions and 5 deletions

3
core/index.d.ts vendored
View file

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

View file

@ -6,6 +6,7 @@ import {
deepseekTemplateMessages,
gemmaTemplateMessage,
llama2TemplateMessages,
llama3TemplateMessages,
llavaTemplateMessages,
neuralChatTemplateMessages,
openchatTemplateMessages,
@ -22,6 +23,7 @@ import {
deepseekEditPrompt,
gemmaEditPrompt,
gptEditPrompt,
llama3EditPrompt,
mistralEditPrompt,
neuralChatEditPrompt,
openchatEditPrompt,
@ -124,6 +126,10 @@ function autodetectTemplateType(model: string): TemplateType | undefined {
return undefined;
}
if (lower.includes("llama3")) {
return "llama3";
}
if (lower.includes("llava")) {
return "llava";
}
@ -218,6 +224,7 @@ function autodetectTemplateFunction(
llava: llavaTemplateMessages,
"codellama-70b": codeLlama70bTemplateMessages,
gemma: gemmaTemplateMessage,
llama3: llama3TemplateMessages,
none: null,
};
@ -241,6 +248,7 @@ const USES_OS_MODELS_EDIT_PROMPT: TemplateType[] = [
"phind",
"xwin-coder",
"zephyr",
"llama3",
];
function autodetectPromptTemplates(
@ -284,6 +292,8 @@ function autodetectPromptTemplates(
editTemplate = claudeEditPrompt;
} else if (templateType === "gemma") {
editTemplate = gemmaEditPrompt;
} else if (templateType === "llama3") {
editTemplate = llama3EditPrompt;
} else if (templateType === "none") {
editTemplate = null;
} else if (templateType) {

View file

@ -254,6 +254,14 @@ function codeLlama70bTemplateMessages(msgs: ChatMessage[]): string {
return prompt;
}
const llama3TemplateMessages = templateFactory(
(msg: ChatMessage) =>
`<|begin_of_text|><|start_header_id|>${msg.role}<|end_header_id|>\n${msg.content}<|eot_id|>\n`,
"<|start_header_id|>user<|end_header_id|>\n",
"<|start_header_id|>assistant<|end_header_id|>\n",
"<|eot_id|>",
);
/**
<start_of_turn>user
What is Cramer's Rule?<end_of_turn>
@ -273,6 +281,7 @@ export {
deepseekTemplateMessages,
gemmaTemplateMessage,
llama2TemplateMessages,
llama3TemplateMessages,
llavaTemplateMessages,
neuralChatTemplateMessages,
openchatTemplateMessages,

View file

@ -259,6 +259,15 @@ Output only a code block with the rewritten code:
},
];
const llama3EditPrompt: PromptTemplate = `<|begin_of_text|><|start_header_id|>user<|end_header_id|>
\`\`\`{{{language}}}
{{{codeToEdit}}}
\`\`\`
Rewrite the above code to satisfy this request: "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
Sure! Here's the code you requested:
\`\`\`{{{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}}}"
@ -279,6 +288,7 @@ export {
deepseekEditPrompt,
gemmaEditPrompt,
gptEditPrompt,
llama3EditPrompt,
mistralEditPrompt,
neuralChatEditPrompt,
openchatEditPrompt,

View file

@ -209,7 +209,8 @@
"neural-chat",
"codellama-70b",
"llava",
"gemma"
"gemma",
"llama3"
],
"type": "string"
},

View file

@ -209,7 +209,8 @@
"neural-chat",
"codellama-70b",
"llava",
"gemma"
"gemma",
"llama3"
],
"type": "string"
},

View file

@ -209,7 +209,8 @@
"neural-chat",
"codellama-70b",
"llava",
"gemma"
"gemma",
"llama3"
],
"type": "string"
},

View file

@ -209,7 +209,8 @@
"neural-chat",
"codellama-70b",
"llava",
"gemma"
"gemma",
"llama3"
],
"type": "string"
},