Skip to content

Commit 91681d4

Browse files
committed
can set chat_template_kwargs in command line
1 parent 46064b4 commit 91681d4

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

common/arg.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,16 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
27902790
params.ssl_file_cert = value;
27912791
}
27922792
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_SSL_CERT_FILE"));
2793+
add_opt(common_arg(
2794+
{"--chat-template-kwargs"}, "STRING",
2795+
string_format("sets additional params for the json template parser"),
2796+
[](common_params & params, const std::string & value) {
2797+
auto parsed = json::parse(value);
2798+
for (const auto & item : parsed.items()) {
2799+
params.default_template_kwargs[item.key()] = item.value().dump();
2800+
}
2801+
}
2802+
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("CHAT_TEMPLATE_KWARGS"));
27932803
add_opt(common_arg(
27942804
{"-to", "--timeout"}, "N",
27952805
string_format("server read/write timeout in seconds (default: %d)", params.timeout_read),

common/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string>
99
#include <string_view>
1010
#include <vector>
11+
#include <map>
1112
#include <sstream>
1213

1314
#ifdef _WIN32
@@ -378,6 +379,8 @@ struct common_params {
378379
std::string ssl_file_key = ""; // NOLINT
379380
std::string ssl_file_cert = ""; // NOLINT
380381

382+
std::map<std::string,std::string> default_template_kwargs;
383+
381384
// "advanced" endpoints are disabled by default for better security
382385
bool webui = true;
383386
bool endpoint_slots = false;

tools/server/server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,7 @@ struct server_context {
20852085
/* use_jinja */ params_base.use_jinja,
20862086
/* prefill_assistant */ params_base.prefill_assistant,
20872087
/* reasoning_format */ params_base.reasoning_format,
2088+
/* chat_template_kwargs */ params_base.default_template_kwargs,
20882089
/* common_chat_templates */ chat_templates.get(),
20892090
/* allow_image */ mctx ? mtmd_support_vision(mctx) : false,
20902091
/* allow_audio */ mctx ? mtmd_support_audio (mctx) : false,

tools/server/utils.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ struct oaicompat_parser_options {
571571
bool use_jinja;
572572
bool prefill_assistant;
573573
common_reasoning_format reasoning_format;
574+
const std::map<std::string,std::string> chat_template_kwargs;
574575
common_chat_templates * tmpls;
575576
bool allow_image;
576577
bool allow_audio;
@@ -749,6 +750,10 @@ static json oaicompat_chat_params_parse(
749750
}
750751

751752
auto chat_template_kwargs_object = json_value(body, "chat_template_kwargs", json::object());
753+
for (const auto & item: default_template_kwargs)
754+
{
755+
inputs.chat_template_kwargs[item.first] = item.second;
756+
}
752757
for (const auto & item : chat_template_kwargs_object.items()) {
753758
inputs.chat_template_kwargs[item.key()] = item.value().dump();
754759
}

0 commit comments

Comments
 (0)