|
|
@@ -59,6 +59,7 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
|
|
|
{ "granite", LLM_CHAT_TEMPLATE_GRANITE },
|
|
|
{ "gigachat", LLM_CHAT_TEMPLATE_GIGACHAT },
|
|
|
{ "megrez", LLM_CHAT_TEMPLATE_MEGREZ },
|
|
|
+ { "yandex", LLM_CHAT_TEMPLATE_YANDEX },
|
|
|
};
|
|
|
|
|
|
llm_chat_template llm_chat_template_from_str(const std::string & name) {
|
|
|
@@ -168,6 +169,8 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
|
|
|
return LLM_CHAT_TEMPLATE_GIGACHAT;
|
|
|
} else if (tmpl_contains("<|role_start|>")) {
|
|
|
return LLM_CHAT_TEMPLATE_MEGREZ;
|
|
|
+ } else if (tmpl_contains(" Ассистент:")) {
|
|
|
+ return LLM_CHAT_TEMPLATE_YANDEX;
|
|
|
}
|
|
|
return LLM_CHAT_TEMPLATE_UNKNOWN;
|
|
|
}
|
|
|
@@ -567,6 +570,24 @@ int32_t llm_chat_apply_template(
|
|
|
if (add_ass) {
|
|
|
ss << "<|role_start|>assistant<|role_end|>";
|
|
|
}
|
|
|
+ } else if (tmpl == LLM_CHAT_TEMPLATE_YANDEX) {
|
|
|
+ // Yandex template ("\n\n" is defined as EOT token)
|
|
|
+
|
|
|
+ ss << "<s>";
|
|
|
+
|
|
|
+ for (size_t i = 0; i < chat.size(); i++) {
|
|
|
+ std::string role(chat[i]->role);
|
|
|
+ if (role == "user") {
|
|
|
+ ss << " Пользователь: " << chat[i]->content << "\n\n";
|
|
|
+ } else if (role == "assistant") {
|
|
|
+ ss << " Ассистент: " << chat[i]->content << "\n\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add generation prompt if needed
|
|
|
+ if (add_ass) {
|
|
|
+ ss << " Ассистент:[SEP]";
|
|
|
+ }
|
|
|
} else {
|
|
|
// template not supported
|
|
|
return -1;
|
|
|
@@ -585,4 +606,3 @@ int32_t llama_chat_builtin_templates(const char ** output, size_t len) {
|
|
|
}
|
|
|
return (int32_t) LLM_CHAT_TEMPLATES.size();
|
|
|
}
|
|
|
-
|