mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-04 02:37:27 +02:00
add props.connect_code
This commit is contained in:
@@ -56,7 +56,7 @@ static std::string format_share_code(const std::string & code) {
|
||||
}
|
||||
|
||||
// whitespace is tolerated, the Web UI shows the code in blocks and users paste it back
|
||||
// returns an empty string if the key is not a valid share code
|
||||
// returns an empty string if it is not a valid share code
|
||||
static std::string normalize_share_code(const std::string & key) {
|
||||
std::string code;
|
||||
for (char c : key) {
|
||||
@@ -161,6 +161,10 @@ std::string server_connect::unavailable_reason(const common_params & params) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string server_connect::resolve_code(const std::string & code) {
|
||||
return code.empty() ? gen_share_code() : normalize_share_code(code);
|
||||
}
|
||||
|
||||
bool server_connect::start(const common_params & params) {
|
||||
const std::string bin = find_binary();
|
||||
if (bin.empty()) {
|
||||
@@ -168,10 +172,9 @@ bool server_connect::start(const common_params & params) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// already validated by unavailable_reason()
|
||||
const std::string code = params.server_connect_code.empty()
|
||||
? gen_share_code()
|
||||
: normalize_share_code(params.server_connect_code);
|
||||
// main() resolves this before anything can read it from /props
|
||||
const std::string & code = params.server_connect_code;
|
||||
GGML_ASSERT(!code.empty());
|
||||
|
||||
// always loopback, params.hostname may be 0.0.0.0 or a unix socket which the child cannot dial
|
||||
const std::vector<std::string> args = {
|
||||
@@ -179,8 +182,8 @@ bool server_connect::start(const common_params & params) {
|
||||
"--host", "127.0.0.1",
|
||||
"--port", std::to_string(params.port),
|
||||
"--code", code,
|
||||
// the kernel closes our end of this pipe even if we are killed without cleanup,
|
||||
// so the child cannot outlive us
|
||||
// the kernel closes our end of this pipe even if we are killed without cleanup
|
||||
// this is what stops the child from outliving us
|
||||
"--exit-on-stdin-eof",
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ struct server_connect {
|
||||
// why --connect cannot work here, empty if it can
|
||||
static std::string unavailable_reason(const common_params & params);
|
||||
|
||||
static std::string resolve_code(const std::string & code);
|
||||
|
||||
bool start(const common_params & params);
|
||||
|
||||
// idempotent, also called by the destructor
|
||||
|
||||
@@ -4618,6 +4618,10 @@ static json get_res_props(const server_context_meta & meta, const common_params
|
||||
{ "is_sleeping", is_sleeping },
|
||||
{ "cors_proxy_enabled", params.ui_mcp_proxy },
|
||||
};
|
||||
|
||||
if (!params.server_connect_code.empty()) {
|
||||
props["connect_code"] = params.server_connect_code;
|
||||
}
|
||||
if (params.use_jinja) {
|
||||
if (!tmpl_tools.empty()) {
|
||||
props["chat_template_tool_use"] = tmpl_tools;
|
||||
|
||||
@@ -1829,7 +1829,7 @@ void server_models_routes::init_routes() {
|
||||
if (name.empty()) {
|
||||
// main instance
|
||||
auto res = std::make_unique<server_http_res>();
|
||||
res_ok(res, {
|
||||
json props = {
|
||||
// TODO: add support for this on web UI
|
||||
{"role", "router"},
|
||||
{"max_instances", params.models_max},
|
||||
@@ -1845,7 +1845,11 @@ void server_models_routes::init_routes() {
|
||||
{"ui_settings", ui_settings},
|
||||
{"build_info", std::string(llama_build_info())},
|
||||
{"cors_proxy_enabled", params.ui_mcp_proxy},
|
||||
});
|
||||
};
|
||||
if (!params.server_connect_code.empty()) {
|
||||
props["connect_code"] = params.server_connect_code;
|
||||
}
|
||||
res_ok(res, props);
|
||||
return res;
|
||||
}
|
||||
return proxy_get(req);
|
||||
|
||||
@@ -183,6 +183,7 @@ int llama_server(common_params & params, int argc, char ** argv) {
|
||||
SRV_ERR("--connect is not available: %s\n", reason.c_str());
|
||||
return 1;
|
||||
}
|
||||
params.server_connect_code = server_connect::resolve_code(params.server_connect_code);
|
||||
}
|
||||
|
||||
// note: this is guaranteed to out-live ctx_http and tools
|
||||
|
||||
Reference in New Issue
Block a user