mirror of
https://gitlab.com/niansa/discord_llama.git
synced 2025-03-06 20:48:25 +01:00
Made status texts configurable
This commit is contained in:
parent
db7351a6c8
commit
62fe173b77
4 changed files with 56 additions and 9 deletions
|
@ -2,6 +2,7 @@ token MTA0MDYxMTQzNjUwNzk1OTMyNw.Gl_iMU.jVVM3bRqBJVi8ORVpWHquOivlASGJpRySt8qFg
|
||||||
|
|
||||||
# The following parameters are set to their defaults here and can be ommited
|
# The following parameters are set to their defaults here and can be ommited
|
||||||
models_dir models
|
models_dir models
|
||||||
|
texts_file none
|
||||||
language EN
|
language EN
|
||||||
threads_only true
|
threads_only true
|
||||||
live_edit false
|
live_edit false
|
||||||
|
|
7
example_texts.txt
Normal file
7
example_texts.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# The following parameters are set to their defaults here and can be ommited
|
||||||
|
please_wait Please wait...
|
||||||
|
thread_create_fail Error: I couldn't create a thread here. Do I have enough permissions?
|
||||||
|
model_missing Error: The model that was used in this thread could no longer be found.
|
||||||
|
timeout Error: Timeout
|
||||||
|
|
||||||
|
translated false
|
|
@ -5,6 +5,9 @@ token MTA0MDYxMTQzNjUwNzk1OTMyNw.Gl_iMU.jVVM3bRqBJVi8ORVpWHquOivlASGJpRySt8qFg
|
||||||
# Directory the models are located in. For example, see example_models/
|
# Directory the models are located in. For example, see example_models/
|
||||||
models_dir models
|
models_dir models
|
||||||
|
|
||||||
|
# File containing status texts. For example, see example_texts.txt
|
||||||
|
texts_file none
|
||||||
|
|
||||||
# Language everything is translated to (will be disabled if set to "EN" anyways)
|
# Language everything is translated to (will be disabled if set to "EN" anyways)
|
||||||
language EN
|
language EN
|
||||||
|
|
||||||
|
|
54
main.cpp
54
main.cpp
|
@ -69,6 +69,13 @@ public:
|
||||||
const ModelConfig *model_config;
|
const ModelConfig *model_config;
|
||||||
bool instruct_mode = false;
|
bool instruct_mode = false;
|
||||||
};
|
};
|
||||||
|
struct Texts {
|
||||||
|
std::string please_wait = "Please wait...",
|
||||||
|
thread_create_fail = "Error: I couldn't create a thread here. Do I have enough permissions?",
|
||||||
|
model_missing = "Error: The model that was used in this thread could no longer be found.",
|
||||||
|
timeout = "Error: Timeout";
|
||||||
|
bool translated = false;
|
||||||
|
};
|
||||||
struct Configuration {
|
struct Configuration {
|
||||||
std::string token,
|
std::string token,
|
||||||
language = "EN",
|
language = "EN",
|
||||||
|
@ -76,7 +83,8 @@ public:
|
||||||
translation_model = "none",
|
translation_model = "none",
|
||||||
prompt_file = "none",
|
prompt_file = "none",
|
||||||
instruct_prompt_file = "none",
|
instruct_prompt_file = "none",
|
||||||
models_dir = "models";
|
models_dir = "models",
|
||||||
|
texts_file = "none";
|
||||||
unsigned ctx_size = 1012,
|
unsigned ctx_size = 1012,
|
||||||
pool_size = 2,
|
pool_size = 2,
|
||||||
timeout = 120,
|
timeout = 120,
|
||||||
|
@ -97,13 +105,7 @@ private:
|
||||||
const Configuration& config;
|
const Configuration& config;
|
||||||
const std::unordered_map<std::string, ModelConfig>& model_configs;
|
const std::unordered_map<std::string, ModelConfig>& model_configs;
|
||||||
|
|
||||||
struct Texts {
|
Texts texts;
|
||||||
std::string please_wait = "Please wait...",
|
|
||||||
thread_create_fail = "Error: I couldn't create a thread here. Do I have enough permissions?",
|
|
||||||
model_missing = "Error: The model that was used in this thread could no longer be found.",
|
|
||||||
timeout = "Error: Timeout";
|
|
||||||
bool translated = false;
|
|
||||||
} texts;
|
|
||||||
|
|
||||||
inline static
|
inline static
|
||||||
bool show_console_progress(float progress) {
|
bool show_console_progress(float progress) {
|
||||||
|
@ -787,6 +789,8 @@ int main(int argc, char **argv) {
|
||||||
cfg.instruct_prompt_file = std::move(value);
|
cfg.instruct_prompt_file = std::move(value);
|
||||||
} else if (key == "models_dir") {
|
} else if (key == "models_dir") {
|
||||||
cfg.models_dir = std::move(value);
|
cfg.models_dir = std::move(value);
|
||||||
|
} else if (key == "texts_file") {
|
||||||
|
cfg.texts_file = std::move(value);
|
||||||
} else if (key == "pool_size") {
|
} else if (key == "pool_size") {
|
||||||
cfg.pool_size = std::stoi(value);
|
cfg.pool_size = std::stoi(value);
|
||||||
} else if (key == "threads") {
|
} else if (key == "threads") {
|
||||||
|
@ -817,6 +821,38 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse texts_file
|
||||||
|
Bot::Texts texts;
|
||||||
|
if (cfg.texts_file != "none") {
|
||||||
|
std::ifstream textsf(cfg.texts_file);
|
||||||
|
if (!textsf) {
|
||||||
|
std::cerr << "Error: Failed to open texts file: " << cfg.texts_file << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
for (std::string key; textsf >> key;) {
|
||||||
|
// Read value
|
||||||
|
std::string value;
|
||||||
|
std::getline(textsf, value);
|
||||||
|
// Erase all leading spaces
|
||||||
|
while (!value.empty() && (value[0] == ' ' || value[0] == '\t')) value.erase(0, 1);
|
||||||
|
// Check key and ignore comment lines
|
||||||
|
if (key == "model_missing") {
|
||||||
|
texts.model_missing = std::move(value);
|
||||||
|
} else if (key == "please_wait") {
|
||||||
|
texts.please_wait = std::move(value);
|
||||||
|
} else if (key == "thread_create_fail") {
|
||||||
|
texts.thread_create_fail = std::move(value);
|
||||||
|
} else if (key == "timeout") {
|
||||||
|
texts.timeout = std::move(value);
|
||||||
|
} else if (key == "translated") {
|
||||||
|
texts.translated = parse_bool(value);
|
||||||
|
} else if (!key.empty() && key[0] != '#') {
|
||||||
|
std::cerr << "Error: Failed to parse texts file: Unknown key: " << key << std::endl;
|
||||||
|
exit(-3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse model configurations
|
// Parse model configurations
|
||||||
std::unordered_map<std::string, Bot::ModelConfig> models;
|
std::unordered_map<std::string, Bot::ModelConfig> models;
|
||||||
std::filesystem::path models_dir(cfg.models_dir);
|
std::filesystem::path models_dir(cfg.models_dir);
|
||||||
|
@ -929,7 +965,7 @@ int main(int argc, char **argv) {
|
||||||
// Construct and configure bot
|
// Construct and configure bot
|
||||||
Bot bot(cfg, models);
|
Bot bot(cfg, models);
|
||||||
|
|
||||||
// Set signal handlers on Linux
|
// Set signal handlers if available
|
||||||
# ifdef sa_sigaction
|
# ifdef sa_sigaction
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
static Bot& bot_st = bot;
|
static Bot& bot_st = bot;
|
||||||
|
|
Loading…
Add table
Reference in a new issue