| 343 | static constexpr size_t FILE_GLOB_MAX_RESULTS = 100; |
| 344 | |
| 345 | int main(int argc, char ** argv) { |
| 346 | common_params params; |
| 347 | |
| 348 | params.verbosity = LOG_LEVEL_ERROR; // by default, less verbose logs |
| 349 | |
| 350 | common_init(); |
| 351 | |
| 352 | if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_CLI)) { |
| 353 | return 1; |
| 354 | } |
| 355 | |
| 356 | // TODO: maybe support it later? |
| 357 | if (params.conversation_mode == COMMON_CONVERSATION_MODE_DISABLED) { |
| 358 | console::error("--no-conversation is not supported by llama-cli\n"); |
| 359 | console::error("please use llama-completion instead\n"); |
| 360 | } |
| 361 | |
| 362 | // struct that contains llama context and inference |
| 363 | cli_context ctx_cli(params); |
| 364 | |
| 365 | llama_backend_init(); |
| 366 | llama_numa_init(params.numa); |
| 367 | |
| 368 | // TODO: avoid using atexit() here by making `console` a singleton |
| 369 | console::init(params.simple_io, params.use_color); |
| 370 | atexit([]() { console::cleanup(); }); |
| 371 | |
| 372 | console::set_display(DISPLAY_TYPE_RESET); |
| 373 | console::set_completion_callback(auto_completion_callback); |
| 374 | |
| 375 | #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) |
| 376 | struct sigaction sigint_action; |
| 377 | sigint_action.sa_handler = signal_handler; |
| 378 | sigemptyset (&sigint_action.sa_mask); |
| 379 | sigint_action.sa_flags = 0; |
| 380 | sigaction(SIGINT, &sigint_action, NULL); |
| 381 | sigaction(SIGTERM, &sigint_action, NULL); |
| 382 | #elif defined (_WIN32) |
| 383 | auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL { |
| 384 | return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false; |
| 385 | }; |
| 386 | SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true); |
| 387 | #endif |
| 388 | |
| 389 | console::log("\nLoading model... "); // followed by loading animation |
| 390 | console::spinner::start(); |
| 391 | if (!ctx_cli.ctx_server.load_model(params)) { |
| 392 | console::spinner::stop(); |
| 393 | console::error("\nFailed to load the model\n"); |
| 394 | return 1; |
| 395 | } |
| 396 | |
| 397 | console::spinner::stop(); |
| 398 | console::log("\n"); |
| 399 | |
| 400 | std::thread inference_thread([&ctx_cli]() { |
| 401 | ctx_cli.ctx_server.start_loop(); |
| 402 | }); |
nothing calls this directly
no test coverage detected