| 354 | } |
| 355 | |
| 356 | int main(int argc, char ** argv) { |
| 357 | // Set log level to most verbose to capture all debug output |
| 358 | common_log_set_verbosity_thold(99); |
| 359 | |
| 360 | debug_options opts; |
| 361 | if (!parse_options(argc, argv, opts)) { |
| 362 | return 1; |
| 363 | } |
| 364 | |
| 365 | if (opts.debug_jinja || std::getenv("LLAMA_DEBUG_JINJA") != nullptr) { |
| 366 | jinja::enable_debug(true); |
| 367 | } |
| 368 | |
| 369 | std::string template_source; |
| 370 | try { |
| 371 | // Check if the file is a GGUF file |
| 372 | if (opts.template_path.size() >= 5 && |
| 373 | opts.template_path.compare(opts.template_path.size() - 5, 5, ".gguf") == 0) { |
| 374 | template_source = read_gguf_chat_template(opts.template_path); |
| 375 | } else { |
| 376 | template_source = read_file(opts.template_path); |
| 377 | } |
| 378 | } catch (const std::exception & e) { |
| 379 | LOG_ERR("Error reading template: %s\n", e.what()); |
| 380 | return 1; |
| 381 | } |
| 382 | |
| 383 | LOG_ERR("Analyzing template: %s\n", opts.template_path.c_str()); |
| 384 | LOG_ERR("Options: with_tools=%s, generation_prompt=%s, enable_reasoning=%s\n", opts.with_tools ? "true" : "false", |
| 385 | opts.generation_prompt ? "true" : "false", opts.enable_reasoning ? "true" : "false"); |
| 386 | |
| 387 | try { |
| 388 | common_chat_template chat_template(template_source, "", ""); |
| 389 | |
| 390 | json tools = opts.with_tools ? build_tools_definition() : json(); |
| 391 | |
| 392 | autoparser::generation_params params = prepare_params(opts, tools); |
| 393 | common_chat_params parser_data; |
| 394 | if (std::optional<common_chat_params> spec_tmpl = |
| 395 | common_chat_try_specialized_template(chat_template, template_source, params)) { |
| 396 | LOG_ERR("\n"); |
| 397 | LOG_ERR("This template uses a specialized parser, analysis results will not be available."); |
| 398 | parser_data = *spec_tmpl; |
| 399 | } else { |
| 400 | // Render template scenarios if requested |
| 401 | if (opts.input_message != input_message_type::NONE && |
| 402 | (opts.mode == output_mode::TEMPLATE || opts.mode == output_mode::BOTH)) { |
| 403 | LOG_ERR("\n"); |
| 404 | LOG_ERR("================================================================================\n"); |
| 405 | LOG_ERR(" TEMPLATE RENDERING OUTPUT\n"); |
| 406 | LOG_ERR("================================================================================\n"); |
| 407 | |
| 408 | render_all_scenarios(chat_template, tools, opts.generation_prompt, opts.enable_reasoning, |
| 409 | opts.input_message); |
| 410 | } |
| 411 | |
| 412 | // Output analysis if requested |
| 413 | if (opts.mode == output_mode::ANALYSIS || opts.mode == output_mode::BOTH) { |
nothing calls this directly
no test coverage detected