|
|
@@ -35,6 +35,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
|
|
|
{ "mistral-v3", LLM_CHAT_TEMPLATE_MISTRAL_V3 },
|
|
|
{ "mistral-v3-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V3_TEKKEN },
|
|
|
{ "mistral-v7", LLM_CHAT_TEMPLATE_MISTRAL_V7 },
|
|
|
+ { "mistral-v7-tekken", LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN },
|
|
|
{ "phi3", LLM_CHAT_TEMPLATE_PHI_3 },
|
|
|
{ "phi4", LLM_CHAT_TEMPLATE_PHI_4 },
|
|
|
{ "falcon3", LLM_CHAT_TEMPLATE_FALCON_3 },
|
|
|
@@ -202,19 +203,20 @@ int32_t llm_chat_apply_template(
|
|
|
if (add_ass) {
|
|
|
ss << "<|im_start|>assistant\n";
|
|
|
}
|
|
|
- } else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7) {
|
|
|
+ } else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 || tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7_TEKKEN) {
|
|
|
// Official mistral 'v7' template
|
|
|
// See: https://huggingface.co/mistralai/Mistral-Large-Instruct-2411#basic-instruct-template-v7
|
|
|
+ // https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#basic-instruct-template-v7-tekken
|
|
|
+ const char * trailing_space = tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V7 ? " " : "";
|
|
|
for (auto message : chat) {
|
|
|
std::string role(message->role);
|
|
|
std::string content(message->content);
|
|
|
if (role == "system") {
|
|
|
- ss << "[SYSTEM_PROMPT] " << content << "[/SYSTEM_PROMPT]";
|
|
|
+ ss << "[SYSTEM_PROMPT]" << trailing_space << content << "[/SYSTEM_PROMPT]";
|
|
|
} else if (role == "user") {
|
|
|
- ss << "[INST] " << content << "[/INST]";
|
|
|
- }
|
|
|
- else {
|
|
|
- ss << " " << content << "</s>";
|
|
|
+ ss << "[INST]" << trailing_space << content << "[/INST]";
|
|
|
+ } else {
|
|
|
+ ss << trailing_space << content << "</s>";
|
|
|
}
|
|
|
}
|
|
|
} else if (tmpl == LLM_CHAT_TEMPLATE_MISTRAL_V1
|