@@ -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
6970llm_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 ;
0 commit comments