diff --git a/llm/ext_server/server.cpp b/llm/ext_server/server.cpp index f5d7863d..22117037 100644 --- a/llm/ext_server/server.cpp +++ b/llm/ext_server/server.cpp @@ -39,6 +39,10 @@ #include "httplib.h" #include "json.hpp" +#if defined(_WIN32) +#include +#endif + #include #include #include @@ -2770,8 +2774,28 @@ inline void signal_handler(int signal) { shutdown_handler(signal); } -int main(int argc, char **argv) -{ +#if defined(_WIN32) +char* wchar_to_char(const wchar_t* wstr) { + if (wstr == nullptr) return nullptr; + + // Determine the number of bytes needed for the UTF-8 string + int bytes = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); + char* str = new char[bytes]; + + // Convert the wide-character string to a UTF-8 string + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, bytes, nullptr, nullptr); + return str; +} + +int wmain(int argc, wchar_t **wargv) { + char** argv = new char*[argc]; + for (int i = 0; i < argc; ++i) { + argv[i] = wchar_to_char(wargv[i]); + } +#else +int main(int argc, char **argv) { +#endif + #if SERVER_VERBOSE != 1 log_disable(); #endif @@ -3282,6 +3306,11 @@ int main(int argc, char **argv) return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false; }; SetConsoleCtrlHandler(reinterpret_cast(console_ctrl_handler), true); + + for (int i = 0; i < argc; ++i) { + delete[] argv[i]; + } + delete[] argv; #endif llama.queue_tasks.start_loop(); svr.stop();