| 365 | } |
| 366 | |
| 367 | static void analyze_template(const std::string & template_path) { |
| 368 | LOG_ERR("\n"); |
| 369 | LOG_ERR("%s", ANSI_PURPLE); |
| 370 | LOG_ERR("================================================================================\n"); |
| 371 | LOG_ERR(" ANALYZING TEMPLATE: %s\n", template_path.c_str()); |
| 372 | LOG_ERR("================================================================================\n"); |
| 373 | LOG_ERR("%s", ANSI_RESET); |
| 374 | |
| 375 | std::string template_source; |
| 376 | try { |
| 377 | template_source = read_file(template_path); |
| 378 | } catch (const std::exception & e) { |
| 379 | LOG_ERR("Error reading template: %s\n", e.what()); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | try { |
| 384 | common_chat_template chat_template(template_source, "", ""); |
| 385 | json tools = build_tools_definition(); |
| 386 | |
| 387 | // ===== CAPABILITIES ANALYSIS ===== |
| 388 | LOG_ERR("\n%s=== Template Capabilities (from jinja::caps) ===%s\n", ANSI_CYAN, ANSI_RESET); |
| 389 | auto caps = chat_template.original_caps(); |
| 390 | LOG_ERR("%ssupports_tools:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_tools ? "true" : "false"); |
| 391 | LOG_ERR("%ssupports_tool_calls:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_tool_calls ? "true" : "false"); |
| 392 | LOG_ERR("%ssupports_system_role:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_system_role ? "true" : "false"); |
| 393 | LOG_ERR("%ssupports_parallel_tool_calls:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_parallel_tool_calls ? "true" : "false"); |
| 394 | LOG_ERR("%ssupports_typed_content:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_typed_content ? "true" : "false"); |
| 395 | LOG_ERR("%ssupports_string_content:%s %s\n", ANSI_BLUE, ANSI_RESET, caps.supports_string_content ? "true" : "false"); |
| 396 | |
| 397 | // ===== DIFFERENTIAL ANALYSIS ===== |
| 398 | |
| 399 | // Test 1: With and without tools (single user message) |
| 400 | { |
| 401 | json user_msg = make_user_msg(); |
| 402 | |
| 403 | autoparser::generation_params params_no_tools; |
| 404 | params_no_tools.messages = json::array({ user_msg }); |
| 405 | params_no_tools.add_generation_prompt = false; |
| 406 | params_no_tools.tools = json::array(); |
| 407 | |
| 408 | autoparser::generation_params params_with_tools = params_no_tools; |
| 409 | params_with_tools.tools = tools; |
| 410 | |
| 411 | std::string output_no_tools = common_chat_template_direct_apply(chat_template, params_no_tools); |
| 412 | std::string output_with_tools = common_chat_template_direct_apply(chat_template, params_with_tools); |
| 413 | |
| 414 | auto diff = calculate_diff_split(output_no_tools, output_with_tools); |
| 415 | print_diff_split("Diff: With vs Without Tools (single user message)", diff); |
| 416 | } |
| 417 | |
| 418 | // Test 2: With and without add_generation_prompt (single user message) |
| 419 | { |
| 420 | json user_msg = make_user_msg(); |
| 421 | |
| 422 | autoparser::generation_params params_no_prompt; |
| 423 | params_no_prompt.messages = json::array({ user_msg }); |
| 424 | params_no_prompt.add_generation_prompt = false; |
no test coverage detected