@@ -35,6 +35,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
35
35
{ " mistral-v3-tekken" , LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
36
36
{ " mistral-v7" , LLM_CHAT_TEMPLATE_MISTRAL_V7 },
37
37
{ " phi3" , LLM_CHAT_TEMPLATE_PHI_3 },
38
+ { " falcon3" , LLM_CHAT_TEMPLATE_FALCON_3 },
38
39
{ " zephyr" , LLM_CHAT_TEMPLATE_ZEPHYR },
39
40
{ " monarch" , LLM_CHAT_TEMPLATE_MONARCH },
40
41
{ " gemma" , LLM_CHAT_TEMPLATE_GEMMA },
@@ -53,6 +54,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
53
54
{ " rwkv-world" , LLM_CHAT_TEMPLATE_RWKV_WORLD },
54
55
{ " granite" , LLM_CHAT_TEMPLATE_GRANITE },
55
56
{ " gigachat" , LLM_CHAT_TEMPLATE_GIGACHAT },
57
+ { " megrez" , LLM_CHAT_TEMPLATE_MEGREZ },
56
58
};
57
59
58
60
llm_chat_template llm_chat_template_from_str (const std::string & name) {
@@ -108,6 +110,8 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
108
110
}
109
111
} else if (tmpl_contains (" <|assistant|>" ) && tmpl_contains (" <|end|>" )) {
110
112
return LLM_CHAT_TEMPLATE_PHI_3;
113
+ } else if (tmpl_contains (" <|assistant|>" ) && tmpl_contains (" <|user|>" )) {
114
+ return LLM_CHAT_TEMPLATE_FALCON_3;
111
115
} else if (tmpl_contains (" <|user|>" ) && tmpl_contains (" <|endoftext|>" )) {
112
116
return LLM_CHAT_TEMPLATE_ZEPHYR;
113
117
} else if (tmpl_contains (" bos_token + message['role']" )) {
@@ -154,6 +158,8 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
154
158
return LLM_CHAT_TEMPLATE_GRANITE;
155
159
} else if (tmpl_contains (" message['role'] + additional_special_tokens[0] + message['content'] + additional_special_tokens[1]" )) {
156
160
return LLM_CHAT_TEMPLATE_GIGACHAT;
161
+ } else if (tmpl_contains (" <|role_start|>" )) {
162
+ return LLM_CHAT_TEMPLATE_MEGREZ;
157
163
}
158
164
return LLM_CHAT_TEMPLATE_UNKNOWN;
159
165
}
@@ -260,6 +266,15 @@ int32_t llm_chat_apply_template(
260
266
if (add_ass) {
261
267
ss << " <|assistant|>\n " ;
262
268
}
269
+ } else if (tmpl == LLM_CHAT_TEMPLATE_FALCON_3) {
270
+ // Falcon 3
271
+ for (auto message : chat) {
272
+ std::string role (message->role );
273
+ ss << " <|" << role << " |>\n " << message->content << " \n " ;
274
+ }
275
+ if (add_ass) {
276
+ ss << " <|assistant|>\n " ;
277
+ }
263
278
} else if (tmpl == LLM_CHAT_TEMPLATE_ZEPHYR) {
264
279
// zephyr template
265
280
for (auto message : chat) {
@@ -503,6 +518,16 @@ int32_t llm_chat_apply_template(
503
518
if (add_ass) {
504
519
ss << " assistant<|role_sep|>" ;
505
520
}
521
+ } else if (tmpl == LLM_CHAT_TEMPLATE_MEGREZ) {
522
+ // Megrez template
523
+ for (auto message : chat) {
524
+ std::string role (message->role );
525
+ ss << " <|role_start|>" << role << " <|role_end|>" << message->content << " <|turn_end|>" ;
526
+ }
527
+
528
+ if (add_ass) {
529
+ ss << " <|role_start|>assistant<|role_end|>" ;
530
+ }
506
531
} else {
507
532
// template not supported
508
533
return -1 ;
0 commit comments