@@ -2923,13 +2923,20 @@ int main(int argc, char ** argv) {
29232923 };
29242924
29252925 const auto handle_props = [&ctx_server, &res_ok](const httplib::Request &, httplib::Response & res) {
2926+ auto chat_template = llama_chat_template_from_model (ctx_server.model , ctx_server.params .chat_template , /* prefer_tool_use= */ false );
29262927 json data = {
29272928 { " default_generation_settings" , ctx_server.default_generation_settings_for_props },
29282929 { " total_slots" , ctx_server.params .n_parallel },
29292930 { " bos_token" , common_token_to_piece (ctx_server.ctx , llama_token_bos (ctx_server.model ), true ) },
29302931 { " eos_token" , common_token_to_piece (ctx_server.ctx , llama_token_eos (ctx_server.model ), true ) },
2931- { " chat_template" , llama_get_chat_template (ctx_server. model ) },
2932+ { " chat_template" , chat_template. source () },
29322933 };
2934+ if (ctx_server.params .use_jinja ) {
2935+ auto tool_use_chat_template = llama_chat_template_from_model (ctx_server.model , ctx_server.params .chat_template , /* prefer_tool_use= */ true );
2936+ if (tool_use_chat_template.source () != chat_template.source ()) {
2937+ data[" chat_template_tool_use" ] = tool_use_chat_template.source ();
2938+ }
2939+ }
29332940
29342941 res_ok (res, data);
29352942 };
@@ -3030,13 +3037,14 @@ int main(int argc, char ** argv) {
30303037 return ;
30313038 }
30323039
3033- static auto chat_template = llama_chat_template_from_model (ctx_server.model , params.chat_template .empty () ? nullptr : params.chat_template .c_str ());
3034- static auto tool_call_style = llama_tool_call_style_detect (chat_template);
3040+ auto body = json::parse (req.body );
3041+ auto chat_template = llama_chat_template_from_model (ctx_server.model , params.chat_template , /* prefer_tool_use= */ body.contains (" tools" ));
3042+ auto tool_call_style = llama_tool_call_style_detect (chat_template);
30353043 LOG_INF (" Tool call style: %s\n " , llama_tool_call_style_name (tool_call_style).c_str ());
30363044
30373045 json data;
30383046 try {
3039- data = oaicompat_completion_params_parse (ctx_server.model , json::parse (req. body ) , chat_template, tool_call_style, params.use_jinja );
3047+ data = oaicompat_completion_params_parse (ctx_server.model , body, chat_template, tool_call_style, params.use_jinja );
30403048 } catch (const std::exception & e) {
30413049 res_error (res, format_error_response (e.what (), ERROR_TYPE_NOT_SUPPORTED));
30423050 return ;
0 commit comments