minja: fix llama_chat_apply_template + adde use_jinja param to validate_model_chat_template

This commit is contained in:
ochafik 2024-09-26 02:14:42 +01:00
parent e983c9d0de
commit 45b243b4a5
2 changed files with 15 additions and 4 deletions

View File

@ -1512,7 +1512,18 @@ std::string llama_detokenize(llama_context * ctx, const std::vector<llama_token>
bool llama_chat_verify_template(const std::string & tmpl, bool use_jinja) {
llama_chat_message chat[] = {{"user", "test"}};
int res = llama_chat_apply_template(nullptr, tmpl.c_str(), chat, 1, true, nullptr, 0, use_jinja);
int res = llama_chat_apply_template(
nullptr,
tmpl.c_str(),
chat,
1,
/* add_ass= */ true,
/* buffer= */ nullptr,
/* length= */ 0,
use_jinja,
/* tools= */ nullptr,
"<s>",
"</s>");
return res >= 0;
}

View File

@ -659,10 +659,10 @@ struct server_context {
return true;
}
bool validate_model_chat_template() const {
bool validate_model_chat_template(bool use_jinja) const {
llama_chat_message chat[] = {{"user", "test"}};
const int res = llama_chat_apply_template(model, nullptr, chat, 1, true, nullptr, 0);
const int res = llama_chat_apply_template(model, nullptr, chat, 1, true, nullptr, 0, use_jinja);
return res > 0;
}
@ -3183,7 +3183,7 @@ int main(int argc, char ** argv) {
// if a custom chat template is not supplied, we will use the one that comes with the model (if any)
if (params.chat_template.empty()) {
if (!ctx_server.validate_model_chat_template()) {
if (!ctx_server.validate_model_chat_template(params.use_jinja)) {
LOG_WRN("%s: The chat template that comes with this model is not yet supported, falling back to chatml. This may cause the model to output suboptimal responses\n", __func__);
params.chat_template = "chatml";
}