|
14 | 14 | #error "Unsupported platform!" |
15 | 15 | #endif |
16 | 16 |
|
17 | | -int main() { |
18 | | - std::string configPath; |
| 17 | +int main(int argc, char *argv[]) { |
19 | 18 |
|
20 | | -#if defined(__APPLE__) && defined(__MACH__) |
21 | | - char path[PATH_MAX]; |
22 | | - uint32_t size = sizeof(path); |
23 | | - if (_NSGetExecutablePath(path, &size) == 0) { |
24 | | - path[size] = '\0'; // Null-terminate the string |
25 | | - char *dir = dirname(path); |
26 | | - configPath = std::string(dir) + "/config/config.json"; |
27 | | - } else { |
28 | | - LOG_ERROR << "Failed to get binary location!"; |
29 | | - return 1; |
30 | | - } |
31 | | -#elif defined(__linux__) |
32 | | - char path[PATH_MAX]; |
33 | | - ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1); |
34 | | - if (len != -1) { |
35 | | - path[len] = '\0'; |
36 | | - char *dir = dirname(path); |
37 | | - configPath = std::string(dir) + "/config/config.json"; |
38 | | - } else { |
39 | | - LOG_ERROR << "Failed to get binary location!"; |
40 | | - return 1; |
41 | | - } |
42 | | -#elif defined(_WIN32) |
43 | | - char path[MAX_PATH]; |
44 | | - char dir[MAX_PATH]; |
45 | | - // char dir[MAX_PATH]; |
46 | | - if (GetModuleFileNameA(NULL, path, sizeof(path))) { |
47 | | - char *lastBackslash = strrchr(path, '\\'); |
48 | | - if (lastBackslash == nullptr) { |
49 | | - return 1; |
50 | | - } |
51 | | - lastBackslash[0] = '\0'; |
52 | | - strcpy(dir, path); |
53 | | - configPath = std::string(dir) + "/config/config.json"; |
54 | | - } else { |
55 | | - LOG_ERROR << "Failed to get binary location!"; |
56 | | - return 1; |
| 19 | + std::string host = "127.0.0.1"; |
| 20 | + int port = 3928; |
| 21 | + |
| 22 | + // Check for host argument |
| 23 | + if (argc > 1) { |
| 24 | + host = argv[1]; |
57 | 25 | } |
58 | | -#else |
59 | | - LOG_ERROR << "Unsupported platform!"; |
60 | | - return 1; |
61 | | -#endif |
62 | 26 |
|
63 | | - // Set HTTP listener address and port |
64 | | - drogon::app().loadConfigFile(configPath); |
65 | | - auto app_conf = drogon::app().getCustomConfig(); |
| 27 | + // Check for port argument |
| 28 | + if (argc > 2) { |
| 29 | + port = std::atoi(argv[2]); // Convert string argument to int |
| 30 | + } |
66 | 31 |
|
67 | | - LOG_INFO << app_conf["llama_model_file"].asString(); |
68 | 32 | nitro_utils::nitro_logo(); |
69 | 33 | LOG_INFO << "Server started, please load your model"; |
70 | | - // drogon::app().addListener("0.0.0.0", 8080); |
| 34 | + drogon::app().addListener(host, port); |
71 | 35 | drogon::app().run(); |
72 | 36 |
|
73 | 37 | return 0; |
|
0 commit comments