LLM for Unity  v2.3.0
Create characters in Unity with LLMs!
Loading...
Searching...
No Matches
LLMChatTemplates.cs
Go to the documentation of this file.
1
3using System.Collections.Generic;
4using System.IO;
5
6namespace LLMUnity
7{
12 public abstract class ChatTemplate
13 {
15 public static string DefaultTemplate;
22 public static Dictionary<string, ChatTemplate> templates;
24 public static ChatTemplate[] templateClasses;
25 public static Dictionary<string, string> templatesDescription;
26 public static Dictionary<string, string> modelTemplates;
27 public static Dictionary<string, string> chatTemplates;
29
30 static ChatTemplate()
31 {
32 DefaultTemplate = "chatml";
33
34 templateClasses = new ChatTemplate[]
35 {
36 new ChatMLTemplate(),
37 new AlpacaTemplate(),
38 new GemmaTemplate(),
43 new LLama2Template(),
44 new Phi3_5Template(),
45 new Phi3Template(),
46 new Phi2Template(),
47 new VicunaTemplate(),
48 new ZephyrTemplate(),
49 };
50
51 templates = new Dictionary<string, ChatTemplate>();
52 templatesDescription = new Dictionary<string, string>();
53 modelTemplates = new Dictionary<string, string>();
54 chatTemplates = new Dictionary<string, string>();
55 foreach (ChatTemplate template in templateClasses)
56 {
57 if (templates.ContainsKey(template.GetName())) LLMUnitySetup.LogError($"{template.GetName()} already in templates");
58 templates[template.GetName()] = template;
59 if (templatesDescription.ContainsKey(template.GetDescription())) LLMUnitySetup.LogError($"{template.GetDescription()} already in templatesDescription");
60 templatesDescription[template.GetDescription()] = template.GetName();
61 foreach (string match in template.GetNameMatches())
62 {
63 if (modelTemplates.ContainsKey(match)) LLMUnitySetup.LogError($"{match} already in modelTemplates");
64 modelTemplates[match] = template.GetName();
65 }
66 foreach (string match in template.GetChatTemplateMatches())
67 {
68 if (chatTemplates.ContainsKey(match)) LLMUnitySetup.LogError($"{match} already in chatTemplates");
69 chatTemplates[match] = template.GetName();
70 }
71 }
72 }
73
80 public static string FromName(string name)
81 {
82 if (name == null) return null;
83 string nameLower = name.ToLower();
84 foreach (var pair in modelTemplates)
85 {
86 if (nameLower.Contains(pair.Key)) return pair.Value;
87 }
88 return null;
89 }
90
96 public static string FromTemplate(string template)
97 {
98 if (template == null) return null;
99 string templateTrim = template.Trim();
100 if (chatTemplates.TryGetValue(templateTrim, out string value))
101 return value;
102 return null;
103 }
104
115 public static string FromGGUF(string path)
116 {
117 return FromGGUF(new GGUFReader(path), path);
118 }
119
120 public static string FromGGUF(GGUFReader reader, string path)
121 {
122 string name;
123 name = FromTemplate(reader.GetStringField("tokenizer.chat_template"));
124 if (name != null) return name;
125
126 name = FromName(reader.GetStringField("general.name"));
127 if (name != null) return name;
128
129 name = FromName(Path.GetFileNameWithoutExtension(path));
130 if (name != null) return name;
131
132 LLMUnitySetup.Log("No chat template could be matched, fallback to ChatML");
133 return DefaultTemplate;
134 }
135
141 public static ChatTemplate GetTemplate(string template)
142 {
143 return templates[template];
144 }
145
147 public virtual string GetName() { return ""; }
149 public virtual string GetDescription() { return ""; }
151 public virtual string[] GetNameMatches() { return new string[] {}; }
153 public virtual string[] GetChatTemplateMatches() { return new string[] {}; }
155 public virtual string[] GetStop(string playerName, string AIName) { return new string[] {}; }
156
157 protected virtual string PromptPrefix() { return ""; }
158 protected virtual string SystemPrefix() { return ""; }
159 protected virtual string SystemSuffix() { return ""; }
160 protected virtual string PlayerPrefix(string playerName) { return ""; }
161 protected virtual string AIPrefix(string AIName) { return ""; }
162 protected virtual string PrefixMessageSeparator() { return ""; }
163 protected virtual string RequestPrefix() { return ""; }
164 protected virtual string RequestSuffix() { return ""; }
165 protected virtual string PairSuffix() { return ""; }
166
172 public virtual string ComputePrompt(List<ChatMessage> messages, string playerName, string AIName, bool endWithPrefix = true)
173 {
174 string chatPrompt = PromptPrefix();
175 int start = 0;
176 if (messages[0].role == "system")
177 {
178 chatPrompt += RequestPrefix() + SystemPrefix() + messages[0].content + SystemSuffix();
179 start = 1;
180 }
181 for (int i = start; i < messages.Count; i += 2)
182 {
183 if (i > start || start == 0) chatPrompt += RequestPrefix();
184 chatPrompt += PlayerPrefix(messages[i].role) + PrefixMessageSeparator() + messages[i].content + RequestSuffix();
185 if (i < messages.Count - 1)
186 {
187 chatPrompt += AIPrefix(messages[i + 1].role) + PrefixMessageSeparator() + messages[i + 1].content + PairSuffix();
188 }
189 }
190 if (endWithPrefix) chatPrompt += AIPrefix(AIName);
191 return chatPrompt;
192 }
193
194 protected string[] AddStopNewlines(string[] stop)
195 {
196 List<string> stopWithNewLines = new List<string>();
197 foreach (string stopword in stop)
198 {
199 stopWithNewLines.Add(stopword);
200 stopWithNewLines.Add("\n" + stopword);
201 }
202 return stopWithNewLines.ToArray();
203 }
204 }
205
211 {
212 public override string GetName() { return "chatml"; }
213 public override string GetDescription() { return "chatml (most widely used)"; }
214 public override string[] GetNameMatches() { return new string[] {"chatml", "hermes", "qwen"}; }
215 public override string[] GetChatTemplateMatches() { return new string[] {"{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"}; }
216
217 protected override string SystemPrefix() { return "<|im_start|>system\n"; }
218 protected override string SystemSuffix() { return "<|im_end|>\n"; }
219 protected override string PlayerPrefix(string playerName) { return $"<|im_start|>{playerName}\n"; }
220 protected override string AIPrefix(string AIName) { return $"<|im_start|>{AIName}\n"; }
221 protected override string RequestSuffix() { return "<|im_end|>\n"; }
222 protected override string PairSuffix() { return "<|im_end|>\n"; }
223
224 public override string[] GetStop(string playerName, string AIName)
225 {
226 return AddStopNewlines(new string[] { "<|im_start|>", "<|im_end|>" });
227 }
228 }
229
235 {
236 public override string GetName() { return "llama"; }
237 public override string GetDescription() { return "llama 2"; }
238
239 protected override string SystemPrefix() { return "<<SYS>>\n"; }
240 protected override string SystemSuffix() { return "\n<</SYS>> "; }
241 protected override string RequestPrefix() { return "<s>[INST] "; }
242 protected override string RequestSuffix() { return " [/INST]"; }
243 protected override string PairSuffix() { return " </s>"; }
244
245 public override string[] GetStop(string playerName, string AIName)
246 {
247 return AddStopNewlines(new string[] { "[INST]", "[/INST]" });
248 }
249 }
250
256 {
257 public override string GetName() { return "llama chat"; }
258 public override string GetDescription() { return "llama 2 (chat)"; }
259 public override string[] GetNameMatches() { return new string[] {"llama-2", "llama v2"}; }
260
261 protected override string PlayerPrefix(string playerName) { return "### " + playerName + ":"; }
262 protected override string AIPrefix(string AIName) { return "### " + AIName + ":"; }
263 protected override string PrefixMessageSeparator() { return " "; }
264
265 public override string[] GetStop(string playerName, string AIName)
266 {
267 return AddStopNewlines(new string[] { "[INST]", "[/INST]", "###" });
268 }
269 }
270
276 {
277 public override string GetName() { return "llama3 chat"; }
278 public override string GetDescription() { return "llama 3 (chat)"; }
279 public override string[] GetNameMatches() { return new string[] {"llama-3", "llama v3"}; }
280 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' }}"};}
281
282 protected override string SystemPrefix() { return "<|start_header_id|>system<|end_header_id|>\n\n"; }
283 protected override string SystemSuffix() { return "<|eot_id|>"; }
284
285 protected override string RequestSuffix() { return "<|eot_id|>"; }
286 protected override string PairSuffix() { return "<|eot_id|>"; }
287
288 protected override string PlayerPrefix(string playerName) { return $"<|start_header_id|>{playerName}<|end_header_id|>\n\n"; }
289 protected override string AIPrefix(string AIName) { return $"<|start_header_id|>{AIName}<|end_header_id|>\n\n"; }
290
291 public override string[] GetStop(string playerName, string AIName)
292 {
293 return AddStopNewlines(new string[] { "<|eot_id|>" });
294 }
295 }
296
302 {
303 public override string GetName() { return "mistral instruct"; }
304 public override string GetDescription() { return "mistral instruct"; }
305
306 protected override string SystemPrefix() { return ""; }
307 protected override string SystemSuffix() { return "\n\n"; }
308 protected override string RequestPrefix() { return "[INST] "; }
309 protected override string RequestSuffix() { return " [/INST]"; }
310 protected override string PairSuffix() { return "</s>"; }
311
312 public override string[] GetStop(string playerName, string AIName)
313 {
314 return AddStopNewlines(new string[] { "</s>", "[INST]", "[/INST]" });
315 }
316 }
317
323 {
324 public override string GetName() { return "mistral chat"; }
325 public override string GetDescription() { return "mistral (chat)"; }
326 public override string[] GetNameMatches() { return new string[] {"mistral"}; }
327 public override string[] GetChatTemplateMatches() { return new string[] {"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"}; }
328
329 protected override string PlayerPrefix(string playerName) { return "### " + playerName + ":"; }
330 protected override string AIPrefix(string AIName) { return "### " + AIName + ":"; }
331 protected override string PrefixMessageSeparator() { return " "; }
332
333 public override string[] GetStop(string playerName, string AIName)
334 {
335 return AddStopNewlines(new string[] { "</s>", "[INST]", "[/INST]", "###" });
336 }
337 }
338
344 {
345 public override string GetName() { return "gemma"; }
346 public override string GetDescription() { return "gemma"; }
347 public override string[] GetNameMatches() { return new string[] {"gemma"}; }
348
349 protected override string RequestSuffix() { return "<end_of_turn>\n"; }
350 protected override string PairSuffix() { return "<end_of_turn>\n"; }
351
352 protected override string PlayerPrefix(string playerName) { return "<start_of_turn>" + playerName + "\n"; }
353 protected override string AIPrefix(string AIName) { return "<start_of_turn>" + AIName + "\n"; }
354
355 public override string ComputePrompt(List<ChatMessage> messages, string playerName, string AIName, bool endWithPrefix = true)
356 {
357 List<ChatMessage> messagesSystemPrompt = messages;
358 if (messages[0].role == "system")
359 {
360 string firstUserMessage = messages[0].content;
361 int start = 1;
362 if (messages.Count > 1)
363 {
364 if (firstUserMessage != "") firstUserMessage += "\n\n";
365 firstUserMessage += messages[1].content;
366 start = 2;
367 }
368 messagesSystemPrompt = new List<ChatMessage>(){new ChatMessage { role = playerName, content = firstUserMessage }};
369 messagesSystemPrompt.AddRange(messages.GetRange(start, messages.Count - start));
370 }
371 return base.ComputePrompt(messagesSystemPrompt, playerName, AIName, endWithPrefix);
372 }
373
374 public override string[] GetStop(string playerName, string AIName)
375 {
376 return AddStopNewlines(new string[] { "<start_of_turn>", "<end_of_turn>" });
377 }
378 }
379
385 {
386 public override string GetName() { return "alpaca"; }
387 public override string GetDescription() { return "alpaca (best alternative)"; }
388 public override string[] GetNameMatches() { return new string[] {"alpaca"}; }
389
390 protected override string SystemSuffix() { return "\n\n"; }
391 protected override string RequestSuffix() { return "\n"; }
392 protected override string PlayerPrefix(string playerName) { return "### " + playerName + ":"; }
393 protected override string AIPrefix(string AIName) { return "### " + AIName + ":"; }
394 protected override string PrefixMessageSeparator() { return " "; }
395 protected override string PairSuffix() { return "\n"; }
396
397 public override string[] GetStop(string playerName, string AIName)
398 {
399 return AddStopNewlines(new string[] { "###" });
400 }
401 }
402
408 {
409 public override string GetName() { return "vicuna"; }
410 public override string GetDescription() { return "vicuna"; }
411 public override string[] GetNameMatches() { return new string[] {"vicuna"}; }
412 public override string[] GetChatTemplateMatches() { return new string[] {"{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{% if message['role'] == 'system' %}{{message['content'] + ' '}}{% elif message['role'] == 'user' %}{{ 'USER: ' + message['content'] + ' '}}{% elif message['role'] == 'assistant' %}{{ 'ASSISTANT: ' + message['content'] + ' '}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'ASSISTANT: '}}{% endif %}"}; }
413
414 protected override string SystemSuffix() { return "\n"; }
415 protected override string PlayerPrefix(string playerName) { return "\n" + playerName + ":"; }
416 protected override string AIPrefix(string AIName) { return "\n" + AIName + ":"; }
417 protected override string PrefixMessageSeparator() { return " "; }
418
419 public override string[] GetStop(string playerName, string AIName)
420 {
421 return AddStopNewlines(new string[] { playerName + ":", AIName + ":" });
422 }
423 }
424
430 {
431 public override string GetName() { return "phi"; }
432 public override string GetDescription() { return "phi-2"; }
433 public override string[] GetNameMatches() { return new string[] {"phi-2"}; }
434
435 protected override string SystemSuffix() { return "\n\n"; }
436 protected override string RequestSuffix() { return "\n"; }
437 protected override string PlayerPrefix(string playerName) { return playerName + ":"; }
438 protected override string AIPrefix(string AIName) { return AIName + ":"; }
439 protected override string PrefixMessageSeparator() { return " "; }
440 protected override string PairSuffix() { return "\n"; }
441
442 public override string[] GetStop(string playerName, string AIName)
443 {
444 return AddStopNewlines(new string[] { playerName + ":", AIName + ":" });
445 }
446 }
447
453 {
454 public override string GetName() { return "phi-3"; }
455 public override string GetDescription() { return "phi-3"; }
456 public override string[] GetNameMatches() { return new string[] {"phi-3"}; }
457 public override string[] GetChatTemplateMatches() { return new string[] {"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}"}; }
458
459 protected override string PlayerPrefix(string playerName) { return $"<|user|>\n"; }
460 protected override string AIPrefix(string AIName) { return $"<|assistant|>\n"; }
461 protected override string RequestSuffix() { return "<|end|>\n"; }
462 protected override string PairSuffix() { return "<|end|>\n"; }
463
464
465 public override string ComputePrompt(List<ChatMessage> messages, string playerName, string AIName, bool endWithPrefix = true)
466 {
467 List<ChatMessage> messagesSystemPrompt = messages;
468 if (messages[0].role == "system")
469 {
470 string firstUserMessage = messages[0].content;
471 int start = 1;
472 if (messages.Count > 1)
473 {
474 if (firstUserMessage != "") firstUserMessage += "\n\n";
475 firstUserMessage += messages[1].content;
476 start = 2;
477 }
478 messagesSystemPrompt = new List<ChatMessage>(){new ChatMessage { role = "user", content = firstUserMessage }};
479 messagesSystemPrompt.AddRange(messages.GetRange(start, messages.Count - start));
480 }
481 return base.ComputePrompt(messagesSystemPrompt, playerName, AIName, endWithPrefix);
482 }
483
484 public override string[] GetStop(string playerName, string AIName)
485 {
486 return AddStopNewlines(new string[] { "<|end|>", "<|user|>", "<|assistant|>" });
487 }
488 }
489
495 {
496 public override string GetName() { return "phi-3.5"; }
497 public override string GetDescription() { return "phi-3.5"; }
498 public override string[] GetNameMatches() { return new string[] {"phi-3.5"}; }
499 public override string[] GetChatTemplateMatches() { return new string[] {"{% for message in messages %}{% if message['role'] == 'system' and message['content'] %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}"};}
500
501 protected override string PlayerPrefix(string playerName) { return $"<|user|>\n"; }
502 protected override string AIPrefix(string AIName) { return $"<|assistant|>\n"; }
503 protected override string RequestSuffix() { return "<|end|>\n"; }
504 protected override string PairSuffix() { return "<|end|>\n"; }
505 protected override string SystemPrefix() { return "<|system|>\n"; }
506 protected override string SystemSuffix() { return "<|end|>\n"; }
507
508 public override string[] GetStop(string playerName, string AIName)
509 {
510 return AddStopNewlines(new string[] { "<|end|>", "<|user|>", "<|assistant|>" });
511 }
512 }
513
519 {
520 public override string GetName() { return "zephyr"; }
521 public override string GetDescription() { return "zephyr"; }
522 public override string[] GetNameMatches() { return new string[] {"zephyr"}; }
523 public override string[] GetChatTemplateMatches() { return new string[] {"{% for message in messages %}\n{% if message['role'] == 'user' %}\n{{ '<|user|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'system' %}\n{{ '<|system|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'assistant' %}\n{{ '<|assistant|>\n' + message['content'] + eos_token }}\n{% endif %}\n{% if loop.last and add_generation_prompt %}\n{{ '<|assistant|>' }}\n{% endif %}\n{% endfor %}"}; }
524
525 protected override string SystemPrefix() { return "<|system|>\n"; }
526 protected override string SystemSuffix() { return "</s>\n"; }
527 protected override string PlayerPrefix(string playerName) { return $"<|user|>\n"; }
528 protected override string AIPrefix(string AIName) { return $"<|assistant|>\n"; }
529 protected override string RequestSuffix() { return "</s>\n"; }
530 protected override string PairSuffix() { return "</s>\n"; }
531
532 public override string[] GetStop(string playerName, string AIName)
533 {
534 return AddStopNewlines(new string[] { $"<|user|>", $"<|assistant|>" });
535 }
536 }
537}
Class implementing the Alpaca template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetDescription()
Returns the chat template description.
override string GetName()
Returns the chat template name.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
Class implementing the ChatML template.
override string GetName()
Returns the chat template name.
override string GetDescription()
Returns the chat template description.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
Class implementing the skeleton of a chat template.
static string FromGGUF(string path)
Determines the chat template name from a GGUF file. It reads the GGUF file and then determines the ch...
virtual string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
static Dictionary< string, ChatTemplate > templates
a dictionary from chat template name to chat template type. It can be used to get the chat template n...
virtual string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
static string FromName(string name)
Determines the chat template name from a search name. It searches if any of the chat template names i...
virtual string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
static ChatTemplate GetTemplate(string template)
Creates the chat template based on the provided chat template name.
virtual string ComputePrompt(List< ChatMessage > messages, string playerName, string AIName, bool endWithPrefix=true)
Constructs the prompt using the template based on a list of ChatMessages.
virtual string GetName()
Returns the chat template name.
virtual string GetDescription()
Returns the chat template description.
static string FromTemplate(string template)
Determines the chat template name from a Jinja template.
static string DefaultTemplate
the default template used when it can't be determined ("chatml")
Class implementing the GGUF reader.
Definition LLMGGUF.cs:55
string GetStringField(string key)
Allows to retrieve a string GGUF field.
Definition LLMGGUF.cs:145
Class implementing the Gemma template.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetDescription()
Returns the chat template description.
override string ComputePrompt(List< ChatMessage > messages, string playerName, string AIName, bool endWithPrefix=true)
Constructs the prompt using the template based on a list of ChatMessages.
override string GetName()
Returns the chat template name.
Class implementing helper functions for setup and process management.
Class implementing a modified version of the LLama2 template for chat.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetDescription()
Returns the chat template description.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string GetName()
Returns the chat template name.
Class implementing the LLama2 template.
override string GetName()
Returns the chat template name.
override string GetDescription()
Returns the chat template description.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
Class implementing the LLama3 template for chat.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string GetName()
Returns the chat template name.
override string GetDescription()
Returns the chat template description.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
Class implementing a modified version of the Mistral Instruct template for chat.
override string GetDescription()
Returns the chat template description.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string GetName()
Returns the chat template name.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
Class implementing the Mistral Instruct template.
override string GetDescription()
Returns the chat template description.
override string GetName()
Returns the chat template name.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
Class implementing the Phi-2 template.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string GetName()
Returns the chat template name.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetDescription()
Returns the chat template description.
Class implementing the Phi-3 template.
override string GetDescription()
Returns the chat template description.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetName()
Returns the chat template name.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string ComputePrompt(List< ChatMessage > messages, string playerName, string AIName, bool endWithPrefix=true)
Constructs the prompt using the template based on a list of ChatMessages.
Class implementing the Phi-3.5 template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string GetName()
Returns the chat template name.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string GetDescription()
Returns the chat template description.
Class implementing the Vicuna template.
override string GetDescription()
Returns the chat template description.
override string GetName()
Returns the chat template name.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
Class implementing the Zephyr template.
override string[] GetChatTemplateMatches()
Returns an array of jinja templates that can be used to match the chat template.
override string GetDescription()
Returns the chat template description.
override string GetName()
Returns the chat template name.
override string[] GetStop(string playerName, string AIName)
Returns an array of the stopwords used by the template.
override string[] GetNameMatches()
Returns an array of names that can be used to match the chat template.