diff --git a/common/tool-call.cpp b/common/tool-call.cpp index 4a4be12d2..9c1ff0036 100644 --- a/common/tool-call.cpp +++ b/common/tool-call.cpp @@ -12,6 +12,27 @@ using json = nlohmann::ordered_json; +std::string llama_tool_call_style_name(llama_tool_call_style style) { + switch (style) { + case llama_tool_call_style::Generic: + return "Generic"; + case llama_tool_call_style::Llama31: + return "Llama-3.1"; + case llama_tool_call_style::Llama32: + return "Llama-3.2"; + case llama_tool_call_style::FunctionaryV3Llama3: + return "FunctionaryV3Llama3"; + case llama_tool_call_style::FunctionaryV3Llama31: + return "FunctionaryV3Llama3.1"; + case llama_tool_call_style::Hermes2Pro: + return "Hermes2Pro"; + case llama_tool_call_style::CommandRPlus: + return "CommandRPlus"; + default: + return "Unknown"; + } +} + llama_tool_call_style llama_tool_call_style_detect(const minja::chat_template & chat_template) { const auto & src = chat_template.source(); diff --git a/common/tool-call.h b/common/tool-call.h index b6911f22e..94f5a04ae 100644 --- a/common/tool-call.h +++ b/common/tool-call.h @@ -35,6 +35,8 @@ struct llama_tool_call_handler { std::vector additional_stop_words; }; +std::string llama_tool_call_style_name(llama_tool_call_style style); + llama_tool_call_style llama_tool_call_style_detect(const minja::chat_template & chat_template); llama_tool_calls parse_tool_calls(llama_tool_call_style style, const nlohmann::ordered_json & tools, const std::string& input); diff --git a/examples/server/server.cpp b/examples/server/server.cpp index 45c295747..303019d37 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -3031,6 +3031,7 @@ int main(int argc, char ** argv) { static auto chat_template = llama_chat_template_from_model(ctx_server.model, params.chat_template.empty() ? nullptr : params.chat_template.c_str()); static auto tool_call_style = llama_tool_call_style_detect(chat_template); + LOG_INF("Tool call style: %s\n", llama_tool_call_style_name(tool_call_style).c_str()); json data; try { diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index 83d3de2da..4ec86bdac 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -468,9 +468,7 @@ static json format_final_response_oaicompat(const json & request, const json & r parsed_tool_calls = parse_tool_calls(tool_call_style, tools, content); if (!parsed_tool_calls.tool_calls.empty()) { finish_reason = "tool_calls"; - if (!parsed_tool_calls.content.empty()) { - message_content = parsed_tool_calls.content; - } + message_content = parsed_tool_calls.content; tool_calls = json::array(); for (const auto & tc : parsed_tool_calls.tool_calls) { tool_calls.push_back({