Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple webchat for server #1998

Merged
merged 18 commits into from
Jul 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switched to fprintf logging and to access_log
  • Loading branch information
tobi committed Jul 4, 2023
commit a30d4b2a8f8dc633b7761accb488dcb464612411
42 changes: 24 additions & 18 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,15 +857,25 @@ static void parse_options_completion(const json & body, llama_server_context & l
LOG_VERBOSE("completion parameters parsed", format_generation_settings(llama));
}


static void log_server_request(const Request & req, const Response & res) {
LOG_INFO("request", {
{ "remote_addr", req.remote_addr },
{ "remote_port", req.remote_port },
{ "status", res.status },
{ "path", req.path },
{ "request", req.body },
// { "response", res.body },
});
std::string referrer = req.has_header("Referer") ? req.get_header_value("Referer") : "-";
std::string user_agent = req.has_header("User-Agent") ? req.get_header_value("User-Agent") : "-";
std::time_t now = std::time(nullptr);
char time_str[80];
std::strftime(time_str, sizeof(time_str), "%d/%b/%Y:%H:%M:%S %z", std::localtime(&now));

fprintf(stdout, "%s - - [%s] \"%s %s HTTP/%s\" %d %zu \"%s\" \"%s\"\n",
req.remote_addr.c_str(),
time_str,
req.method.c_str(),
req.path.c_str(),
"1.1",
res.status,
res.body.size(),
referrer.c_str(),
user_agent.c_str()
);
}

int main(int argc, char ** argv) {
Expand Down Expand Up @@ -1070,20 +1080,16 @@ int main(int argc, char ** argv) {
svr.set_read_timeout(sparams.read_timeout);
svr.set_write_timeout(sparams.write_timeout);

// Set the base directory for serving static files
svr.set_base_dir(sparams.public_path);

if (!svr.bind_to_port(sparams.hostname, sparams.port)) {
LOG_ERROR("couldn't bind to server socket", {
{ "hostname", sparams.hostname },
{ "port", sparams.port },
});
fprintf(stderr, "\ncouldn't bind to server socket: hostname=%s port=%d\n\n", sparams.hostname.c_str(), sparams.port);
return 1;
}

std::cout << std::endl;
std::cout << "llama server listening at http://" << sparams.hostname << ":" << sparams.port << std::endl;
std::cout << std::endl;
// Set the base directory for serving static files
svr.set_base_dir(sparams.public_path);

fprintf(stdout, "\nllama server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stdout, "\nllama server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
fprintf(stderr, "\nllama server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);

This needs to not go out with the JSON logs otherwise they could not be parsed correctly.

I think stderr is OK for this because other parts of llama.cpp also log there.



if (!svr.listen_after_bind()) {
return 1;
Expand Down