llama : fix chat template gguf key (#11201)

This commit is contained in:
Xuan Son Nguyen 2025-01-12 13:45:14 +01:00 committed by GitHub
parent 08f10f69c3
commit 9a483999a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 10 deletions

View file

@ -1636,15 +1636,8 @@ std::string common_detokenize(const struct llama_vocab * vocab, const std::vecto
//
std::string common_get_builtin_chat_template(const struct llama_model * model) {
static const char * template_key = "tokenizer.chat_template";
// call with NULL buffer to get the total size of the string
int32_t res = llama_model_meta_val_str(model, template_key, NULL, 0);
if (res > 0) {
std::vector<char> model_template(res + 1, 0);
llama_model_meta_val_str(model, template_key, model_template.data(), model_template.size());
return std::string(model_template.data(), model_template.size() - 1);
}
return "";
const char * ptr_tmpl = llama_model_chat_template(model);
return ptr_tmpl == nullptr ? "" : ptr_tmpl;
}
bool common_chat_verify_template(const std::string & tmpl) {