Simple single-line server log for requests

This commit is contained in:
digiwombat 2023-05-31 15:56:27 -04:00
parent 96fa480147
commit 7332b41f9f

View file

@ -750,8 +750,11 @@ int main(int argc, char **argv)
Server svr; Server svr;
svr.Get("/", [](const Request &, Response &res) svr.Get("/", [](const Request &req, Response &res)
{ res.set_content("<h1>llama.cpp server works</h1>", "text/html"); }); {
fprintf(stderr, "request: GET / [remote_addr: %s]", req.remote_addr.c_str());
res.set_content("<h1>llama.cpp server works</h1>", "text/html");
});
svr.Post("/completion", [&llama](const Request &req, Response &res) { svr.Post("/completion", [&llama](const Request &req, Response &res) {
if (llama.params.embedding) { if (llama.params.embedding) {
@ -772,6 +775,8 @@ int main(int argc, char **argv)
return; return;
} }
fprintf(stderr, "request: POST /completion [remote_addr: %s, stream: %s]", req.remote_addr.c_str(), llama.stream ? "true" : "false");
if (!llama.loadPrompt()) { if (!llama.loadPrompt()) {
json data = {{"status", "error"}, {"reason", "Context too long."}}; json data = {{"status", "error"}, {"reason", "Context too long."}};
res.set_content( res.set_content(
@ -885,6 +890,7 @@ int main(int argc, char **argv)
svr.Post("/tokenize", [&llama](const Request &req, Response &res) svr.Post("/tokenize", [&llama](const Request &req, Response &res)
{ {
fprintf(stderr, "request: POST /tokenize [remote_addr: %s]", req.remote_addr.c_str());
json body = json::parse(req.body); json body = json::parse(req.body);
json data = { json data = {
{"tokens", ::llama_tokenize(llama.ctx, body["content"].get<std::string>(), false) } }; {"tokens", ::llama_tokenize(llama.ctx, body["content"].get<std::string>(), false) } };
@ -893,6 +899,7 @@ int main(int argc, char **argv)
svr.Post("/embedding", [&llama](const Request &req, Response &res) svr.Post("/embedding", [&llama](const Request &req, Response &res)
{ {
fprintf(stderr, "request: POST /embedding [remote_addr: %s]", req.remote_addr.c_str());
if(!llama.params.embedding) { if(!llama.params.embedding) {
std::vector<float> empty; std::vector<float> empty;
json data = { json data = {