Skip to content

Commit 41103c0

Browse files
author
ochafik
committed
server: add --chat-template-file
1 parent e309c6a commit 41103c0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

common/arg.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,33 @@ gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex,
18681868
params.chat_template = value;
18691869
}
18701870
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
1871+
add_opt(llama_arg(
1872+
{"--chat-template-file"}, "JINJA_TEMPLATE_FILE",
1873+
"set custom jinja chat template file (default: template taken from model's metadata)\n"
1874+
"if suffix/prefix are specified, template will be disabled\n"
1875+
"only commonly used templates are accepted (unless --jinja is set before this flag):\n"
1876+
"https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template",
1877+
[](gpt_params & params, const std::string & value) {
1878+
std::ifstream file(value);
1879+
if (!file) {
1880+
throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
1881+
}
1882+
std::string chat_template;
1883+
std::copy(
1884+
std::istreambuf_iterator<char>(file),
1885+
std::istreambuf_iterator<char>(),
1886+
std::back_inserter(chat_template)
1887+
);
1888+
if (!llama_chat_verify_template(chat_template, params.use_jinja)) {
1889+
throw std::runtime_error(format(
1890+
"error: the supplied chat template is not supported: %s\n"
1891+
"note: llama.cpp does not use jinja parser, we only support commonly used templates\n",
1892+
chat_template.c_str()
1893+
));
1894+
}
1895+
params.chat_template = chat_template;
1896+
}
1897+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
18711898
add_opt(llama_arg(
18721899
{"-sps", "--slot-prompt-similarity"}, "SIMILARITY",
18731900
format("how much the prompt of a request must match the prompt of a slot in order to use that slot (default: %.2f, 0.0 = disabled)\n", params.slot_prompt_similarity),

0 commit comments

Comments
 (0)