server : headers cleanup

This commit is contained in:
Georgi Gerganov 2025-11-24 10:43:56 +02:00
parent 625010d42d
commit 72f80499ee
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735
5 changed files with 19 additions and 17 deletions

View File

@ -9,6 +9,9 @@
#include "server-common.h" #include "server-common.h"
#include <random>
#include <sstream>
json format_error_response(const std::string & message, const enum error_type type) { json format_error_response(const std::string & message, const enum error_type type) {
std::string type_str; std::string type_str;
int code = 500; int code = 500;

View File

@ -5,27 +5,14 @@
#include "llama.h" #include "llama.h"
#include "chat.h" #include "chat.h"
#include "mtmd.h" #include "mtmd.h"
#include "mtmd-helper.h"
#define JSON_ASSERT GGML_ASSERT #define JSON_ASSERT GGML_ASSERT
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <random>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include <cinttypes> #include <cinttypes>
// fix problem with std::min and std::max
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
#endif
#define DEFAULT_OAICOMPAT_MODEL "gpt-3.5-turbo" #define DEFAULT_OAICOMPAT_MODEL "gpt-3.5-turbo"
const static std::string build_info("b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT); const static std::string build_info("b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT);

View File

@ -3,6 +3,8 @@
#include "log.h" #include "log.h"
#include <chrono>
#define QUE_INF(fmt, ...) LOG_INF("que %12.*s: " fmt, 12, __func__, __VA_ARGS__) #define QUE_INF(fmt, ...) LOG_INF("que %12.*s: " fmt, 12, __func__, __VA_ARGS__)
#define QUE_WRN(fmt, ...) LOG_WRN("que %12.*s: " fmt, 12, __func__, __VA_ARGS__) #define QUE_WRN(fmt, ...) LOG_WRN("que %12.*s: " fmt, 12, __func__, __VA_ARGS__)
#define QUE_ERR(fmt, ...) LOG_ERR("que %12.*s: " fmt, 12, __func__, __VA_ARGS__) #define QUE_ERR(fmt, ...) LOG_ERR("que %12.*s: " fmt, 12, __func__, __VA_ARGS__)

View File

@ -2,7 +2,6 @@
#include "server-task.h" #include "server-task.h"
#include <chrono>
#include <condition_variable> #include <condition_variable>
#include <deque> #include <deque>
#include <mutex> #include <mutex>

View File

@ -10,6 +10,7 @@
#include "sampling.h" #include "sampling.h"
#include "speculative.h" #include "speculative.h"
#include "mtmd.h" #include "mtmd.h"
#include "mtmd-helper.h"
#include <atomic> #include <atomic>
#include <cstddef> #include <cstddef>
@ -19,6 +20,15 @@
#include <thread> #include <thread>
#include <unordered_set> #include <unordered_set>
// fix problem with std::min and std::max
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
#endif
using json = nlohmann::ordered_json; using json = nlohmann::ordered_json;
constexpr int HTTP_POLLING_SECONDS = 1; constexpr int HTTP_POLLING_SECONDS = 1;
@ -3597,10 +3607,10 @@ private:
} }
}; };
std::function<void(int)> shutdown_handler; static std::function<void(int)> shutdown_handler;
std::atomic_flag is_terminating = ATOMIC_FLAG_INIT; static std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;
inline void signal_handler(int signal) { static inline void signal_handler(int signal) {
if (is_terminating.test_and_set()) { if (is_terminating.test_and_set()) {
// in case it hangs, we can force terminate the server by hitting Ctrl+C twice // in case it hangs, we can force terminate the server by hitting Ctrl+C twice
// this is for better developer experience, we can remove when the server is stable enough // this is for better developer experience, we can remove when the server is stable enough
@ -3769,6 +3779,7 @@ int main(int argc, char ** argv) {
ctx_server.queue_tasks.terminate(); ctx_server.queue_tasks.terminate();
}; };
// TODO: refactor in common/console
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
struct sigaction sigint_action; struct sigaction sigint_action;
sigint_action.sa_handler = signal_handler; sigint_action.sa_handler = signal_handler;