Skip to content

Commit cb88292

Browse files
ggerganovhazelnutcloud
authored andcommitted
server : print chat template info
1 parent fa4ffdc commit cb88292

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

examples/server/server.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,8 @@ static void server_print_usage(const char * argv0, const gpt_params & params, co
21972197
printf(" -gaw N, --grp-attn-w N set the group attention width to extend context size through self-extend(default: 512), used together with group attention factor `--grp-attn-n`\n");
21982198
printf(" --chat-template JINJA_TEMPLATE\n");
21992199
printf(" set custom jinja chat template (default: template taken from model's metadata)\n");
2200-
printf(" Note: only commonly used templates are accepted, since we don't have jinja parser\n");
2200+
printf(" only commonly used templates are accepted:\n");
2201+
printf(" https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template\n");
22012202
printf("\n");
22022203
}
22032204

@@ -2798,13 +2799,30 @@ int main(int argc, char ** argv) {
27982799

27992800
const auto model_meta = ctx_server.model_meta();
28002801

2801-
if (sparams.chat_template.empty()) { // custom chat template is not supplied
2802+
// if a custom chat template is not supplied, we will use the one that comes with the model (if any)
2803+
if (sparams.chat_template.empty()) {
28022804
if (!ctx_server.validate_model_chat_template()) {
28032805
LOG_ERROR("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", {});
28042806
sparams.chat_template = "chatml";
28052807
}
28062808
}
28072809

2810+
// print sample chat example to make it clear which template is used
2811+
{
2812+
json chat;
2813+
chat.push_back({{"role", "system"}, {"content", "You are a helpful assistant"}});
2814+
chat.push_back({{"role", "user"}, {"content", "Hello"}});
2815+
chat.push_back({{"role", "assistant"}, {"content", "Hi there"}});
2816+
chat.push_back({{"role", "user"}, {"content", "How are you?"}});
2817+
2818+
const std::string chat_example = format_chat(ctx_server.model, sparams.chat_template, chat);
2819+
2820+
LOG_INFO("chat template", {
2821+
{"chat_example", chat_example},
2822+
{"built_in", sparams.chat_template.empty()},
2823+
});
2824+
}
2825+
28082826
//
28092827
// Middlewares
28102828
//

0 commit comments

Comments
 (0)