char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
c264f65ff
char/aliceai-t5-moe
1#include "arg.h" 2#include "common.h" 3#include "log.h" 4 5#include "cli-context.h" 6 7#include <signal.h> 8 9#if defined(_WIN32 ) 10#define WIN32_LEAN_AND_MEAN 11#ifndef NOMINMAX 12# define NOMINMAX 13#endif 14#include <windows.h> 15#endif 16 17#if defined (__unix__ )|| (defined (__APPLE__ )&& defined (__MACH__ ))|| defined (_WIN32 ) 18static void signal_handler (int ) { 19if (cli_context::interrupted ().load ()) { 20// second Ctrl+C - exit immediately 21// make sure to clear colors before exiting (not using LOG or console.cpp here to avoid deadlock) 22fprintf (stdout ,"\033[0m\n" ); 23fflush (stdout ); 24 std::exit (130 ); 25 } 26 cli_context::interrupted ().store (true); 27} 28#endif 29 30// satisfies -Wmissing-declarations 31int llama_cli (int argc ,char ** argv ); 32 33int llama_cli (int argc ,char ** argv ) { 34common_params params ; 35 36params .verbosity = LOG_LEVEL_ERROR ;// by default, less verbose logs 37 38common_init (); 39 40if (!common_params_parse (argc ,argv ,params ,LLAMA_EXAMPLE_CLI )) { 41return 1 ; 42 } 43 44#if defined (__unix__ )|| (defined (__APPLE__ )&& defined (__MACH__ )) 45struct sigaction sigint_action ; 46sigint_action .sa_handler = signal_handler ; 47sigemptyset (& sigint_action .sa_mask ); 48sigint_action .sa_flags = 0 ; 49sigaction (SIGINT ,& sigint_action ,NULL ); 50sigaction (SIGTERM ,& sigint_action ,NULL ); 51#elif defined (_WIN32 ) 52auto console_ctrl_handler = + [](DWORD ctrl_type )-> BOOL { 53return (ctrl_type == CTRL_C_EVENT ) ? (signal_handler (SIGINT ), true) : false; 54 }; 55SetConsoleCtrlHandler (reinterpret_cast < PHANDLER_ROUTINE > (console_ctrl_handler ), true); 56#endif 57 58cli_context ctx_cli (params ); 59 60if (!ctx_cli .init ()) { 61return 1 ; 62 } 63 64return ctx_cli .run (); 65}