diff --git a/common/chat.cpp b/common/chat.cpp index 1fedb0230..00f30994b 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -473,11 +473,12 @@ std::string common_chat_format_single( return ss.str(); } -std::string common_chat_format_example(const struct common_chat_templates * tmpls, bool use_jinja) { +std::string common_chat_format_example(const struct common_chat_templates * tmpls, bool use_jinja, const std::map & chat_template_kwargs) { common_chat_templates_inputs inputs; inputs.use_jinja = use_jinja; inputs.add_bos = tmpls->add_bos; inputs.add_eos = tmpls->add_eos; + inputs.chat_template_kwargs = chat_template_kwargs; auto add_simple_msg = [&](auto role, auto content) { common_chat_msg msg; msg.role = role; diff --git a/common/chat.h b/common/chat.h index c4d6b2e85..d1e480c91 100644 --- a/common/chat.h +++ b/common/chat.h @@ -187,7 +187,8 @@ std::string common_chat_format_single( // Returns an example of formatted chat std::string common_chat_format_example( const struct common_chat_templates * tmpls, - bool use_jinja); + bool use_jinja, + const std::map & chat_template_kwargs); const char* common_chat_format_name(common_chat_format format); const char* common_reasoning_format_name(common_reasoning_format format); diff --git a/tools/main/main.cpp b/tools/main/main.cpp index eb36c6884..dc776f59e 100644 --- a/tools/main/main.cpp +++ b/tools/main/main.cpp @@ -220,7 +220,7 @@ int main(int argc, char ** argv) { LOG_WRN("*** User-specified prompt will pre-start conversation, did you mean to set --system-prompt (-sys) instead?\n"); } - LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(chat_templates.get(), params.use_jinja).c_str()); + LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(chat_templates.get(), params.use_jinja, params.default_template_kwargs).c_str()); } else { LOG_INF("%s: in-suffix/prefix is specified, chat template will be disabled\n", __func__); } diff --git a/tools/mtmd/mtmd-cli.cpp b/tools/mtmd/mtmd-cli.cpp index 599e682e0..5fde6ca0c 100644 --- a/tools/mtmd/mtmd-cli.cpp +++ b/tools/mtmd/mtmd-cli.cpp @@ -108,7 +108,7 @@ struct mtmd_cli_context { } tmpls = common_chat_templates_init(model, params.chat_template); - LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(tmpls.get(), params.use_jinja).c_str()); + LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(tmpls.get(), params.use_jinja, params.default_template_kwargs).c_str()); init_vision_context(params); diff --git a/tools/server/server.cpp b/tools/server/server.cpp index 8578d49e0..0b40f7bfa 100644 --- a/tools/server/server.cpp +++ b/tools/server/server.cpp @@ -2053,7 +2053,7 @@ struct server_context { chat_templates = common_chat_templates_init(model, params_base.chat_template); try { - common_chat_format_example(chat_templates.get(), params.use_jinja); + common_chat_format_example(chat_templates.get(), params.use_jinja, params.default_template_kwargs); } catch (const std::exception & e) { SRV_WRN("%s: Chat template parsing error: %s\n", __func__, e.what()); SRV_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__); @@ -5075,7 +5075,7 @@ int main(int argc, char ** argv) { // print sample chat example to make it clear which template is used LOG_INF("%s: chat template, chat_template: %s, example_format: '%s'\n", __func__, common_chat_templates_source(ctx_server.chat_templates.get()), - common_chat_format_example(ctx_server.chat_templates.get(), ctx_server.params_base.use_jinja).c_str()); + common_chat_format_example(ctx_server.chat_templates.get(), ctx_server.params_base.use_jinja, ctx_server.params_base.default_template_kwargs).c_str()); ctx_server.queue_tasks.on_new_task([&ctx_server](server_task && task) { ctx_server.process_single_task(std::move(task));