char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Xuan-Son Nguyencli : move to HTTP-based implementation (#24948)c264f65ff

char/aliceai-t5-moe
1.7 KiB65 linesraw
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) {
19    if (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)
22        fprintf(stdout, "\033[0m\n");
23        fflush(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) {
34    common_params params;
35
36    params.verbosity = LOG_LEVEL_ERROR; // by default, less verbose logs
37
38    common_init();
39
40    if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_CLI)) {
41        return 1;
42    }
43
44#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
45    struct sigaction sigint_action;
46    sigint_action.sa_handler = signal_handler;
47    sigemptyset (&sigint_action.sa_mask);
48    sigint_action.sa_flags = 0;
49    sigaction(SIGINT, &sigint_action, NULL);
50    sigaction(SIGTERM, &sigint_action, NULL);
51#elif defined (_WIN32)
52    auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
53        return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
54    };
55    SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
56#endif
57
58    cli_context ctx_cli(params);
59
60    if (!ctx_cli.init()) {
61        return 1;
62    }
63
64    return ctx_cli.run();
65}