Skip to content

server : (webui) let server send locally-defined default webui settings #14468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3416,5 +3416,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
}
).set_examples({LLAMA_EXAMPLE_SERVER}));

add_opt(common_arg(
{"--default-client-config"}, "JSON_FNAME",
string_format("JSON file containing the default client config"),
[](common_params & params, const std::string & value) {
params.public_default_client_config = value;
}
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_DEFAULT_CLIENT_CONFIG"));

return ctx_arg;
}
1 change: 1 addition & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ struct common_params {

std::string hostname = "127.0.0.1";
std::string public_path = ""; // NOLINT
std::string public_default_client_config = ""; // NOLINT
std::string chat_template = ""; // NOLINT
bool use_jinja = false; // NOLINT
bool enable_chat_template = true;
Expand Down
Binary file modified tools/server/public/index.html.gz
Binary file not shown.
17 changes: 17 additions & 0 deletions tools/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstddef>
#include <cinttypes>
#include <deque>
#include <fstream>
#include <memory>
#include <mutex>
#include <signal.h>
Expand Down Expand Up @@ -1905,6 +1906,7 @@ struct server_context {
// slots / clients
std::vector<server_slot> slots;
json default_generation_settings_for_props;
json default_client_config = json::object();

server_queue queue_tasks;
server_response queue_results;
Expand Down Expand Up @@ -2097,6 +2099,15 @@ struct server_context {

default_generation_settings_for_props = slots[0].to_json();

if (!params_base.public_default_client_config.empty()) {
std::ifstream file(params_base.public_default_client_config);
LOG_INF("%s: Loading default client config from %s\n", __func__, params_base.public_default_client_config.c_str());
if (!file.is_open()) {
throw std::runtime_error("Error: default client config file not open");
}
file >> default_client_config;
}

// the update_slots() logic will always submit a maximum of n_batch or n_parallel tokens
// note that n_batch can be > n_ctx (e.g. for non-causal attention models such as BERT where the KV cache is not used)
{
Expand Down Expand Up @@ -3851,6 +3862,11 @@ int main(int argc, char ** argv) {
res_ok(res, health);
};

const auto handle_default_config = [&](const httplib::Request &, httplib::Response & res) {
// default client-side config
res_ok(res, ctx_server.default_client_config);
};

const auto handle_slots = [&](const httplib::Request & req, httplib::Response & res) {
if (!params.endpoint_slots) {
res_error(res, format_error_response("This server does not support slots endpoint. Start it with `--slots`", ERROR_TYPE_NOT_SUPPORTED));
Expand Down Expand Up @@ -4830,6 +4846,7 @@ int main(int argc, char ** argv) {

// register API routes
svr->Get ("/health", handle_health); // public endpoint (no API key check)
svr->Get ("/defaultConfig.json", handle_default_config); // public endpoint (no API key check)
svr->Get ("/metrics", handle_metrics);
svr->Get ("/props", handle_props);
svr->Post("/props", handle_props_change);
Expand Down
14 changes: 13 additions & 1 deletion tools/server/webui/src/components/SettingDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useAppContext } from '../utils/app.context';
import { CONFIG_DEFAULT, CONFIG_INFO } from '../Config';
import { isDev } from '../Config';
Expand Down Expand Up @@ -285,6 +285,18 @@
);
const { showConfirm, showAlert } = useModals();

// get default client settings
useEffect(() => {
StorageUtils.setDefaultConfig().then((wasChanged: boolean) => {
if (wasChanged) {
console.log('Setting default config');
const newConfig = StorageUtils.getConfig();
saveConfig(newConfig);
setLocalConfig(JSON.parse(JSON.stringify(newConfig)));
}
});
}, []);

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (Release)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (Release)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (ADDRESS, RelWithDebInfo)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (ADDRESS, RelWithDebInfo)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (UNDEFINED, RelWithDebInfo)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

Check warning on line 298 in tools/server/webui/src/components/SettingDialog.tsx

View workflow job for this annotation

GitHub Actions / server (UNDEFINED, RelWithDebInfo)

React Hook useEffect has a missing dependency: 'saveConfig'. Either include it or remove the dependency array

const resetConfig = async () => {
if (await showConfirm('Are you sure you want to reset all settings?')) {
setLocalConfig(CONFIG_DEFAULT);
Expand Down
17 changes: 17 additions & 0 deletions tools/server/webui/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ const StorageUtils = {
localStorage.setItem('theme', theme);
}
},
async setDefaultConfig(): Promise<boolean> {
if (localStorage.getItem('config') === null) {
try {
const response = await fetch('/defaultConfig.json');
const defaultConfig = await response.json();

// Ensure there still is no config when we overwrite it
if (localStorage.getItem('config') === null) {
localStorage.setItem('config', JSON.stringify(defaultConfig));
}
return true;
} catch (e) {
console.error(e);
}
}
return false;
},
};

export default StorageUtils;
Expand Down
Loading