Switch to the CPPHTTPLIB logger. Verbose adds body dump as well as request info.
This commit is contained in:
parent
7332b41f9f
commit
dda4c10d64
1 changed files with 18 additions and 11 deletions
|
@ -750,11 +750,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
svr.Get("/", [](const Request &req, Response &res)
|
svr.Get("/", [](const Request &, 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) {
|
||||||
|
@ -775,8 +772,6 @@ 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(
|
||||||
|
@ -890,7 +885,6 @@ 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) } };
|
||||||
|
@ -899,7 +893,6 @@ 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 = {
|
||||||
|
@ -921,7 +914,21 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (llama.verbose) {
|
if (llama.verbose) {
|
||||||
svr.set_logger([](const Request& req, const Response& res) {
|
svr.set_logger([](const Request& req, const Response& res) {
|
||||||
fprintf(stderr, "%s", log(req, res).c_str());
|
json log = {
|
||||||
|
{ "status", res.status },
|
||||||
|
{ "request", req.body },
|
||||||
|
{ "response", res.body },
|
||||||
|
};
|
||||||
|
fprintf(stdout, "http_request: request: %s %s \nhttp_request: log: %s\n", req.method.c_str(), req.path.c_str(), log.dump().c_str());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
svr.set_logger([](const Request& req, const Response& res) {
|
||||||
|
json log = {
|
||||||
|
{ "status", res.status },
|
||||||
|
{ "request", req.body },
|
||||||
|
{ "response", res.body },
|
||||||
|
};
|
||||||
|
fprintf(stdout, "http_request: request: %s %s \n", req.method.c_str(), req.path.c_str());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue