Skip to content

Commit 51886a4

Browse files
committed
chat template
1 parent cb1f9f2 commit 51886a4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/llama-chat.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
6464
{ "bailing", LLM_CHAT_TEMPLATE_BAILING },
6565
{ "llama4", LLM_CHAT_TEMPLATE_LLAMA4 },
6666
{ "smolvlm", LLM_CHAT_TEMPLATE_SMOLVLM },
67+
{ "hunyuan-moe", LLM_CHAT_TEMPLATE_HUNYUAN_MOE },
6768
};
6869

6970
llm_chat_template llm_chat_template_from_str(const std::string & name) {
@@ -185,6 +186,8 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
185186
return LLM_CHAT_TEMPLATE_LLAMA4;
186187
} else if (tmpl_contains("<|endofuserprompt|>")) {
187188
return LLM_CHAT_TEMPLATE_DOTS1;
189+
} else if (tmpl_contains("<|startoftext|>") && tmpl_contains("<|extra_4|>")) {
190+
return LLM_CHAT_TEMPLATE_HUNYUAN_MOE;
188191
}
189192
return LLM_CHAT_TEMPLATE_UNKNOWN;
190193
}
@@ -665,6 +668,21 @@ int32_t llm_chat_apply_template(
665668
if (add_ass) {
666669
ss << "<|response|>";
667670
}
671+
} else if (tmpl == LLM_CHAT_TEMPLATE_HUNYUAN_MOE) {
672+
// tencent/Hunyuan-A13B-Instruct
673+
for (auto message : chat) {
674+
std::string role(message->role);
675+
if (role == "system") {
676+
ss << "<|startoftext|>" << message->content << "<|extra_4|>";
677+
} else if (role == "assistant") {
678+
ss << "<|startoftext|>" << message->content << "<|eos|>";
679+
} else {
680+
ss << "<|startoftext|>" << message->content << "<|extra_0|>";
681+
}
682+
}
683+
if (add_ass) {
684+
ss << "<|startoftext|>";
685+
}
668686
} else {
669687
// template not supported
670688
return -1;

src/llama-chat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum llm_chat_template {
4444
LLM_CHAT_TEMPLATE_LLAMA4,
4545
LLM_CHAT_TEMPLATE_SMOLVLM,
4646
LLM_CHAT_TEMPLATE_DOTS1,
47+
LLM_CHAT_TEMPLATE_HUNYUAN_MOE,
4748
LLM_CHAT_TEMPLATE_UNKNOWN,
4849
};
4950

0 commit comments

Comments
 (0)