Skip to content

Commit 38321cb

Browse files
committed
add llama3 chat template
1 parent 16034c3 commit 38321cb

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

Runtime/LLMChatTemplates.cs

+31-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static ChatTemplate()
4040
new MistralInstructTemplate(),
4141
new LLama2ChatTemplate(),
4242
new LLama2Template(),
43+
new LLama3ChatTemplate(),
4344
new Phi2Template(),
4445
new VicunaTemplate(),
4546
new ZephyrTemplate(),
@@ -229,7 +230,7 @@ public override string[] GetStop(string playerName, string AIName)
229230
public class LLama2Template : ChatTemplate
230231
{
231232
public override string GetName() { return "llama"; }
232-
public override string GetDescription() { return "llama"; }
233+
public override string GetDescription() { return "llama 2"; }
233234

234235
protected override string SystemPrefix() { return "<<SYS>>\n"; }
235236
protected override string SystemSuffix() { return "\n<</SYS>> "; }
@@ -250,8 +251,8 @@ public override string[] GetStop(string playerName, string AIName)
250251
public class LLama2ChatTemplate : LLama2Template
251252
{
252253
public override string GetName() { return "llama chat"; }
253-
public override string GetDescription() { return "llama (modified for chat)"; }
254-
public override string[] GetNameMatches() { return new string[] {"llama"}; }
254+
public override string GetDescription() { return "llama 2 (modified for chat)"; }
255+
public override string[] GetNameMatches() { return new string[] {"llama-2", "llama v2"}; }
255256

256257
protected override string PlayerPrefix(string playerName) { return "### " + playerName + ":"; }
257258
protected override string AIPrefix(string AIName) { return "### " + AIName + ":"; }
@@ -263,6 +264,33 @@ public override string[] GetStop(string playerName, string AIName)
263264
}
264265
}
265266

267+
/// @ingroup template
268+
/// <summary>
269+
/// Class implementing the LLama3 template for chat
270+
/// </summary>
271+
public class LLama3ChatTemplate : ChatTemplate
272+
{
273+
public override string GetName() { return "llama3 chat"; }
274+
public override string GetDescription() { return "llama 3 (chat)"; }
275+
public override string[] GetNameMatches() { return new string[] {"llama-3", "llama v3"}; }
276+
public override string[] GetChatTemplateMatches() { return new string[] {"{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}"};}
277+
278+
protected override string PromptPrefix() { return "<|begin_of_text|>"; }
279+
protected override string SystemPrefix() { return "<|start_header_id|>system<|end_header_id|>\n\n"; }
280+
protected override string SystemSuffix() { return "<|eot_id|>"; }
281+
282+
protected override string RequestSuffix() { return "<|eot_id|>"; }
283+
protected override string PairSuffix() { return "<|eot_id|>"; }
284+
285+
protected override string PlayerPrefix(string playerName) { return $"<|start_header_id|>{playerName}<|end_header_id|>\n\n"; }
286+
protected override string AIPrefix(string AIName) { return $"<|start_header_id|>{AIName}<|end_header_id|>\n\n"; }
287+
288+
public override string[] GetStop(string playerName, string AIName)
289+
{
290+
return AddStopNewlines(new string[] { "<|eot_id|>" });
291+
}
292+
}
293+
266294
/// @ingroup template
267295
/// <summary>
268296
/// Class implementing the Mistral Instruct template

0 commit comments

Comments
 (0)