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

Commit 91cb3a9

Browse files
committed
Merge branch 'dev' of https://github.com/menloresearch/cortex.cpp into s/chore/rm-vcpkg
2 parents 94f6435 + 552db8f commit 91cb3a9

19 files changed

+292
-108
lines changed

engine/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ project(cortex-server C CXX)
55
include(CheckIncludeFileCXX)
66

77
set(CMAKE_CXX_STANDARD 17)
8-
MESSAGE("CMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD})
9-
108
set(CMAKE_CXX_STANDARD_REQUIRED ON)
119
set(CMAKE_CXX_EXTENSIONS OFF)
12-
# set(OPENSSL_USE_STATIC_LIBS TRUE)
1310
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1411

1512
# Add CORTEX_CQA option

engine/cli/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,9 @@ project(cortex C CXX)
22

33
include(CheckIncludeFileCXX)
44

5-
check_include_file_cxx(any HAS_ANY)
6-
check_include_file_cxx(string_view HAS_STRING_VIEW)
7-
check_include_file_cxx(coroutine HAS_COROUTINE)
8-
if(HAS_ANY
9-
AND HAS_STRING_VIEW
10-
AND HAS_COROUTINE)
11-
set(CMAKE_CXX_STANDARD 20)
12-
elseif(HAS_ANY AND HAS_STRING_VIEW)
13-
set(CMAKE_CXX_STANDARD 17)
14-
else()
15-
set(CMAKE_CXX_STANDARD 14)
16-
endif()
17-
5+
set(CMAKE_CXX_STANDARD 17)
186
set(CMAKE_CXX_STANDARD_REQUIRED ON)
197
set(CMAKE_CXX_EXTENSIONS OFF)
20-
set(OPENSSL_USE_STATIC_LIBS TRUE)
218
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
229

2310
if(MSVC)

engine/cli/command_line_parser.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
8686
#else
8787
CLI_LOG("default");
8888
#endif
89-
(void) c;
89+
(void)c;
9090
};
9191
app_.add_flag_function("-v,--version", cb, "Get Cortex version");
9292

@@ -436,7 +436,7 @@ void CommandLineParser::SetupConfigsCommands() {
436436

437437
auto is_empty = true;
438438
for (const auto& [key, value] : config_update_opts_) {
439-
if (!value.empty() || CONFIGURATIONS.at(key).allow_empty) {
439+
if (!value.empty() || key == "api_keys") {
440440
is_empty = false;
441441
break;
442442
}

engine/cli/commands/config_upd_cmd.cc

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "commands/server_start_cmd.h"
33
#include "common/api_server_configuration.h"
44
#include "utils/curl_utils.h"
5+
#include "utils/file_manager_utils.h"
56
#include "utils/logging_utils.h"
67
#include "utils/string_utils.h"
78
#include "utils/url_parser.h"
@@ -46,22 +47,40 @@ inline Json::Value NormalizeJson(
4647
void commands::ConfigUpdCmd::Exec(
4748
const std::string& host, int port,
4849
const std::unordered_map<std::string, std::string>& options) {
49-
if (!commands::IsServerAlive(host, port)) {
50-
CLI_LOG("Starting server ...");
51-
commands::ServerStartCmd ssc;
52-
if (!ssc.Exec(host, port)) {
53-
return;
54-
}
55-
}
5650

5751
auto non_null_opts = std::unordered_map<std::string, std::string>();
5852
for (const auto& [key, value] : options) {
59-
if (value.empty() && !CONFIGURATIONS.at(key).allow_empty) {
53+
// In case of api_keys, we allow empty value
54+
if (value.empty() && key != "api_keys") {
6055
continue;
6156
}
6257
non_null_opts[key] = value;
6358
}
6459

60+
if (non_null_opts.size() == 1) {
61+
for (const auto& [key, value] : non_null_opts) {
62+
if (key == "api_keys") {
63+
auto config = file_manager_utils::GetCortexConfig();
64+
config.apiKeys = string_utils::SplitBy(value, ",");
65+
auto result = file_manager_utils::UpdateCortexConfig(config);
66+
if (result.has_error()) {
67+
CLI_LOG_ERROR(result.error());
68+
} else {
69+
CLI_LOG("Configuration updated successfully!");
70+
}
71+
return;
72+
}
73+
}
74+
}
75+
76+
if (!commands::IsServerAlive(host, port)) {
77+
CLI_LOG("Starting server ...");
78+
commands::ServerStartCmd ssc;
79+
if (!ssc.Exec(host, port)) {
80+
return;
81+
}
82+
}
83+
6584
auto url = url_parser::Url{
6685
/* .protocol = */ "http",
6786
/* .host = */ host + ":" + std::to_string(port),

engine/cli/commands/engine_update_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool EngineUpdateCmd::Exec(const std::string& host, int port,
4545
try {
4646
Json::Value json = json_helper::ParseJsonString(update_result.error());
4747
std::cout << json["message"].asString() << std::endl;
48-
} catch (const std::exception& e) {
48+
} catch (const std::exception&) {
4949
CTL_ERR(update_result.error());
5050
}
5151

engine/common/api_server_configuration.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ static const std::unordered_map<std::string, ApiConfigurationMetadata>
8080
/* .accept_value = */ "string",
8181
/* .default_value = */ "",
8282
/* .allow_empty = */ true}},
83+
{"api_keys",
84+
ApiConfigurationMetadata{
85+
/* .name = */ "api_keys",
86+
/* .desc = */ "API header key to get access to server APIs",
87+
/* .group = */ "Token",
88+
/* .accept_value = */ " comma separated",
89+
/* .default_value = */ "",
90+
/* .allow_empty = */ true}},
91+
8392
};
8493

8594
class ApiServerConfiguration {
@@ -316,4 +325,4 @@ class ApiServerConfiguration {
316325
}
317326
}
318327
};
319-
};
328+
};

engine/config/gguf_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void GGUFHandler::OpenFile(const std::string& file_path) {
8686
#endif
8787
}
8888

89-
void GGUFHandler::CheckOffset(int offset) const {
89+
void GGUFHandler::CheckOffset(size_t offset) const {
9090
if (offset > file_size_)
9191
throw std::runtime_error("Unexpected EOF");
9292
}

engine/config/gguf_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GGUFHandler {
4747
size_t ReadArray(std::size_t offset, const std::string& key);
4848
void ModelConfigFromMetadata();
4949
void OpenFile(const std::string& file_path);
50-
void CheckOffset(int offset) const;
50+
void CheckOffset(size_t offset) const;
5151

5252
uint8_t* data_;
5353
size_t file_size_;

engine/config/yaml_config.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void YamlHandler::ReadYamlFile(const std::string& file_path) {
5555
}
5656
}
5757

58-
} catch (const YAML::BadFile& e) {
58+
} catch (const YAML::BadFile&) {
5959
throw;
6060
}
6161
}

engine/database/engines.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ std::optional<EngineEntry> Engines::UpsertEngine(
6060
} else {
6161
return std::nullopt;
6262
}
63-
} catch (const std::exception& e) {
63+
} catch (const std::exception&) {
6464
return std::nullopt;
6565
}
6666
}
@@ -87,7 +87,7 @@ std::optional<std::vector<EngineEntry>> Engines::GetEngines() const {
8787
}
8888

8989
return engines;
90-
} catch (const std::exception& e) {
90+
} catch (const std::exception&) {
9191
return std::nullopt;
9292
}
9393
}
@@ -115,7 +115,7 @@ std::optional<EngineEntry> Engines::GetEngineById(int id) const {
115115
} else {
116116
return std::nullopt;
117117
}
118-
} catch (const std::exception& e) {
118+
} catch (const std::exception&) {
119119
return std::nullopt;
120120
}
121121
}
@@ -155,7 +155,7 @@ std::optional<EngineEntry> Engines::GetEngineByNameAndVariant(
155155
} else {
156156
return std::nullopt;
157157
}
158-
} catch (const std::exception& e) {
158+
} catch (const std::exception&) {
159159
return std::nullopt;
160160
}
161161
}

0 commit comments

Comments
 (0)