| 275 | } |
| 276 | |
| 277 | int main(int argc, char ** argv) { |
| 278 | std::setlocale(LC_NUMERIC, "C"); |
| 279 | |
| 280 | ggml_time_init(); |
| 281 | |
| 282 | common_params params; |
| 283 | |
| 284 | common_init(); |
| 285 | |
| 286 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_MTMD, show_additional_info)) { |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | mtmd_helper_log_set(common_log_default_callback, nullptr); |
| 291 | |
| 292 | if (params.mmproj.path.empty()) { |
| 293 | show_additional_info(argc, argv); |
| 294 | LOG_ERR("ERR: Missing --mmproj argument\n"); |
| 295 | return 1; |
| 296 | } |
| 297 | |
| 298 | mtmd_cli_context ctx(params); |
| 299 | LOG_INF("%s: loading model: %s\n", __func__, params.model.path.c_str()); |
| 300 | |
| 301 | bool is_single_turn = !params.prompt.empty() && !params.image.empty(); |
| 302 | |
| 303 | int n_predict = params.n_predict < 0 ? INT_MAX : params.n_predict; |
| 304 | |
| 305 | // Ctrl+C handling |
| 306 | { |
| 307 | #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) |
| 308 | struct sigaction sigint_action; |
| 309 | sigint_action.sa_handler = sigint_handler; |
| 310 | sigemptyset (&sigint_action.sa_mask); |
| 311 | sigint_action.sa_flags = 0; |
| 312 | sigaction(SIGINT, &sigint_action, NULL); |
| 313 | #elif defined (_WIN32) |
| 314 | auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL { |
| 315 | return (ctrl_type == CTRL_C_EVENT) ? (sigint_handler(SIGINT), true) : false; |
| 316 | }; |
| 317 | SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true); |
| 318 | #endif |
| 319 | } |
| 320 | |
| 321 | if (g_is_interrupted) return 130; |
| 322 | |
| 323 | auto eval_system_prompt_if_present = [&] { |
| 324 | if (params.system_prompt.empty()) { |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | common_chat_msg msg; |
| 329 | msg.role = "system"; |
| 330 | msg.content = params.system_prompt; |
| 331 | return eval_message(ctx, msg); |
| 332 | }; |
| 333 | |
| 334 | LOG_WRN("WARN: This is an experimental CLI for testing multimodal capability.\n"); |
nothing calls this directly
no test coverage detected