@@ -35,6 +35,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
3535 { " mistral-v3" , LLM_CHAT_TEMPLATE_MISTRAL_V3 },
3636 { " mistral-v3-tekken" , LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
3737 { " mistral-v7" , LLM_CHAT_TEMPLATE_MISTRAL_V7 },
38+ { " mistral-v7-tekken" , LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN },
3839 { " phi3" , LLM_CHAT_TEMPLATE_PHI_3 },
3940 { " phi4" , LLM_CHAT_TEMPLATE_PHI_4 },
4041 { " falcon3" , LLM_CHAT_TEMPLATE_FALCON_3 },
@@ -202,19 +203,20 @@ int32_t llm_chat_apply_template(
202203 if (add_ass) {
203204 ss << " <|im_start|>assistant\n " ;
204205 }
205- } else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7) {
206+ } else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 || tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN ) {
206207 // Official mistral 'v7' template
207208 // See: https://huggingface.co/mistralai/Mistral-Large-Instruct-2411#basic-instruct-template-v7
209+ // https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#basic-instruct-template-v7-tekken
210+ const char * trailing_space = tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 ? " " : " " ;
208211 for (auto message : chat) {
209212 std::string role (message->role );
210213 std::string content (message->content );
211214 if (role == " system" ) {
212- ss << " [SYSTEM_PROMPT] " << content << " [/SYSTEM_PROMPT]" ;
215+ ss << " [SYSTEM_PROMPT]" << trailing_space << content << " [/SYSTEM_PROMPT]" ;
213216 } else if (role == " user" ) {
214- ss << " [INST] " << content << " [/INST]" ;
215- }
216- else {
217- ss << " " << content << " </s>" ;
217+ ss << " [INST]" << trailing_space << content << " [/INST]" ;
218+ } else {
219+ ss << trailing_space << content << " </s>" ;
218220 }
219221 }
220222 } else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V1
0 commit comments