Update server.cpp
This commit is contained in:
parent
58ad3c3ad2
commit
139cdfc0de
1 changed files with 22 additions and 21 deletions
|
@ -2801,6 +2801,28 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
httplib::Server svr;
|
httplib::Server svr;
|
||||||
|
|
||||||
|
svr.set_default_headers({{"Server", "llama.cpp"},
|
||||||
|
{"Access-Control-Allow-Origin", "*"},
|
||||||
|
{"Access-Control-Allow-Headers", "content-type"}});
|
||||||
|
|
||||||
|
svr.Get("/health", [&](const httplib::Request&, httplib::Response& res) {
|
||||||
|
switch(server_state) {
|
||||||
|
case READY:
|
||||||
|
res.set_content(R"({"status": "ok"})", "application/json");
|
||||||
|
res.status = 200; // HTTP OK
|
||||||
|
break;
|
||||||
|
case LOADING_MODEL:
|
||||||
|
res.set_content(R"({"status": "loading model"})", "application/json");
|
||||||
|
res.status = 503; // HTTP Service Unavailable
|
||||||
|
break;
|
||||||
|
case ERROR:
|
||||||
|
res.set_content(R"({"status": "error", "error": "Model failed to load"})", "application/json");
|
||||||
|
res.status = 500; // HTTP Internal Server Error
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
ServerState server_state = LOADING_MODEL;
|
ServerState server_state = LOADING_MODEL;
|
||||||
// load the model
|
// load the model
|
||||||
if (!llama.load_model(params))
|
if (!llama.load_model(params))
|
||||||
|
@ -2839,9 +2861,6 @@ int main(int argc, char **argv)
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
svr.set_default_headers({{"Server", "llama.cpp"},
|
|
||||||
{"Access-Control-Allow-Origin", "*"},
|
|
||||||
{"Access-Control-Allow-Headers", "content-type"}});
|
|
||||||
|
|
||||||
// this is only called if no index.html is found in the public --path
|
// this is only called if no index.html is found in the public --path
|
||||||
svr.Get("/", [](const httplib::Request &, httplib::Response &res)
|
svr.Get("/", [](const httplib::Request &, httplib::Response &res)
|
||||||
|
@ -2951,24 +2970,6 @@ int main(int argc, char **argv)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
svr.Get("/health", [&](const httplib::Request&, httplib::Response& res) {
|
|
||||||
switch(server_state) {
|
|
||||||
case READY:
|
|
||||||
res.set_content(R"({"status": "ok"})", "application/json");
|
|
||||||
res.status = 200; // HTTP OK
|
|
||||||
break;
|
|
||||||
case LOADING_MODEL:
|
|
||||||
res.set_content(R"({"status": "loading model"})", "application/json");
|
|
||||||
res.status = 503; // HTTP Service Unavailable
|
|
||||||
break;
|
|
||||||
case ERROR:
|
|
||||||
res.set_content(R"({"status": "error", "error": "Model failed to load"})", "application/json");
|
|
||||||
res.status = 500; // HTTP Internal Server Error
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
svr.Get("/v1/models", [¶ms](const httplib::Request&, httplib::Response& res)
|
svr.Get("/v1/models", [¶ms](const httplib::Request&, httplib::Response& res)
|
||||||
{
|
{
|
||||||
std::time_t t = std::time(0);
|
std::time_t t = std::time(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue