Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 571e03b

Browse files
committed
feat: add dynamic loading model through api
1 parent 4cfa440 commit 571e03b

File tree

1 file changed

+12
-48
lines changed

1 file changed

+12
-48
lines changed

main.cc

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,24 @@
1414
#error "Unsupported platform!"
1515
#endif
1616

17-
int main() {
18-
std::string configPath;
17+
int main(int argc, char *argv[]) {
1918

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];
5725
}
58-
#else
59-
LOG_ERROR << "Unsupported platform!";
60-
return 1;
61-
#endif
6226

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+
}
6631

67-
LOG_INFO << app_conf["llama_model_file"].asString();
6832
nitro_utils::nitro_logo();
6933
LOG_INFO << "Server started, please load your model";
70-
// drogon::app().addListener("0.0.0.0", 8080);
34+
drogon::app().addListener(host, port);
7135
drogon::app().run();
7236

7337
return 0;

0 commit comments

Comments
 (0)