| 452 | } |
| 453 | |
| 454 | bool common_chat_verify_template(const std::string & tmpl, bool use_jinja) { |
| 455 | if (use_jinja) { |
| 456 | try { |
| 457 | common_chat_msg msg; |
| 458 | msg.role = "user"; |
| 459 | msg.content = "test"; |
| 460 | |
| 461 | auto tmpls = common_chat_templates_init(/* model= */ nullptr, tmpl); |
| 462 | |
| 463 | common_chat_templates_inputs inputs; |
| 464 | inputs.messages = { msg }; |
| 465 | |
| 466 | common_chat_templates_apply(tmpls.get(), inputs); |
| 467 | return true; |
| 468 | } catch (const std::exception & e) { |
| 469 | LOG_ERR("%s: failed to apply template: %s\n", __func__, e.what()); |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | llama_chat_message chat[] = { |
| 474 | { "user", "test" } |
| 475 | }; |
| 476 | const int res = llama_chat_apply_template(tmpl.c_str(), chat, 1, true, nullptr, 0); |
| 477 | return res >= 0; |
| 478 | } |
| 479 | |
| 480 | std::string common_chat_format_single(const struct common_chat_templates * tmpls, |
| 481 | const std::vector<common_chat_msg> & past_msg, |
no test coverage detected