MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

smallthinker/tools/server/server.cpp:3661–4964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3659}
3660
3661int main(int argc, char ** argv) {
3662 // own arguments required by this example
3663 common_params params;
3664
3665 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_SERVER)) {
3666 return 1;
3667 }
3668
3669 common_init();
3670
3671 // struct that contains llama context and inference
3672 server_context ctx_server;
3673
3674 llama_backend_init();
3675 llama_numa_init(params.numa);
3676
3677 LOG_INF("system info: n_threads = %d, n_threads_batch = %d, total_threads = %d\n", params.cpuparams.n_threads, params.cpuparams_batch.n_threads, std::thread::hardware_concurrency());
3678 LOG_INF("\n");
3679 LOG_INF("%s\n", common_params_get_system_info(params).c_str());
3680 LOG_INF("\n");
3681
3682 std::unique_ptr<httplib::Server> svr;
3683#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3684 if (params.ssl_file_key != "" && params.ssl_file_cert != "") {
3685 LOG_INF("Running with SSL: key = %s, cert = %s\n", params.ssl_file_key.c_str(), params.ssl_file_cert.c_str());
3686 svr.reset(
3687 new httplib::SSLServer(params.ssl_file_cert.c_str(), params.ssl_file_key.c_str())
3688 );
3689 } else {
3690 LOG_INF("Running without SSL\n");
3691 svr.reset(new httplib::Server());
3692 }
3693#else
3694 if (params.ssl_file_key != "" && params.ssl_file_cert != "") {
3695 LOG_ERR("Server is built without SSL support\n");
3696 return 1;
3697 }
3698 svr.reset(new httplib::Server());
3699#endif
3700
3701 std::atomic<server_state> state{SERVER_STATE_LOADING_MODEL};
3702
3703 svr->set_default_headers({{"Server", "llama.cpp"}});
3704 svr->set_logger(log_server_request);
3705
3706 auto res_error = [](httplib::Response & res, const json & error_data) {
3707 json final_response {{"error", error_data}};
3708 res.set_content(safe_json_to_str(final_response), MIMETYPE_JSON);
3709 res.status = json_value(error_data, "code", 500);
3710 };
3711
3712 auto res_ok = [](httplib::Response & res, const json & data) {
3713 res.set_content(safe_json_to_str(data), MIMETYPE_JSON);
3714 res.status = 200;
3715 };
3716
3717 svr->set_exception_handler([&res_error](const httplib::Request &, httplib::Response & res, const std::exception_ptr & ep) {
3718 std::string message;

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
common_initFunction · 0.85
llama_numa_initFunction · 0.85
safe_json_to_strFunction · 0.85
format_error_responseFunction · 0.85
maxFunction · 0.85
fs_validate_filenameFunction · 0.85
common_token_to_pieceFunction · 0.85
llama_vocab_bosFunction · 0.85
llama_vocab_eosFunction · 0.85

Tested by

no test coverage detected