examplse : de-shadow

ggml-ci
This commit is contained in:
Georgi Gerganov 2025-01-12 14:25:32 +02:00
parent 82caffa74e
commit 9a735ae6d8
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
16 changed files with 152 additions and 159 deletions

View file

@ -17,19 +17,19 @@
using json = nlohmann::ordered_json;
common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
this->examples = std::move(examples);
common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> vals) {
examples = std::move(vals);
return *this;
}
common_arg & common_arg::set_excludes(std::initializer_list<enum llama_example> excludes) {
this->excludes = std::move(excludes);
common_arg & common_arg::set_excludes(std::initializer_list<enum llama_example> vals) {
excludes = std::move(vals);
return *this;
}
common_arg & common_arg::set_env(const char * env) {
help = help + "\n(env: " + env + ")";
this->env = env;
common_arg & common_arg::set_env(const char * val) {
help = help + "\n(env: " + val + ")";
env = val;
return *this;
}
@ -46,8 +46,10 @@ bool common_arg::is_exclude(enum llama_example ex) {
return excludes.find(ex) != excludes.end();
}
bool common_arg::get_value_from_env(std::string & output) {
if (env == nullptr) return false;
bool common_arg::get_value_from_env(std::string & output) const {
if (env == nullptr) {
return false;
}
char * value = std::getenv(env);
if (value) {
output = value;
@ -56,7 +58,7 @@ bool common_arg::get_value_from_env(std::string & output) {
return false;
}
bool common_arg::has_value_from_env() {
bool common_arg::has_value_from_env() const {
return env != nullptr && std::getenv(env);
}
@ -87,7 +89,7 @@ static std::vector<std::string> break_str_into_lines(std::string input, size_t m
return result;
}
std::string common_arg::to_string() {
std::string common_arg::to_string() const {
// params for printing to console
const static int n_leading_spaces = 40;
const static int n_char_per_line_help = 70; // TODO: detect this based on current console
@ -192,8 +194,6 @@ static std::string get_all_kv_cache_types() {
//
static bool common_params_parse_ex(int argc, char ** argv, common_params_context & ctx_arg) {
std::string arg;
const std::string arg_prefix = "--";
common_params & params = ctx_arg.params;
std::unordered_map<std::string, common_arg *> arg_to_options;

View file

@ -53,15 +53,15 @@ struct common_arg {
void (*handler)(common_params & params, const std::string &, const std::string &)
) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {}
common_arg & set_examples(std::initializer_list<enum llama_example> examples);
common_arg & set_excludes(std::initializer_list<enum llama_example> excludes);
common_arg & set_env(const char * env);
common_arg & set_examples(std::initializer_list<enum llama_example> vals);
common_arg & set_excludes(std::initializer_list<enum llama_example> vals);
common_arg & set_env(const char * val);
common_arg & set_sparam();
bool in_example(enum llama_example ex);
bool is_exclude(enum llama_example ex);
bool get_value_from_env(std::string & output);
bool has_value_from_env();
std::string to_string();
bool get_value_from_env(std::string & output) const;
bool has_value_from_env() const;
std::string to_string() const;
};
struct common_params_context {

View file

@ -763,9 +763,11 @@ bool fs_create_directory_with_parents(const std::string & path) {
return true;
#else
// if the path already exists, check whether it's a directory
struct stat info;
if (stat(path.c_str(), &info) == 0) {
return S_ISDIR(info.st_mode);
{
struct stat info;
if (stat(path.c_str(), &info) == 0) {
return S_ISDIR(info.st_mode);
}
}
size_t pos_slash = 1; // skip leading slashes for directory creation
@ -796,7 +798,7 @@ bool fs_create_directory_with_parents(const std::string & path) {
}
std::string fs_get_cache_directory() {
std::string cache_directory = "";
std::string cache_directory;
auto ensure_trailing_slash = [](std::string p) {
// Make sure to add trailing slash
if (p.back() != DIRECTORY_SEPARATOR) {

View file

@ -43,7 +43,7 @@ namespace console {
static bool simple_io = true;
static display_t current_display = reset;
static FILE* out = stdout;
static FILE* fout = stdout;
#if defined (_WIN32)
static void* hConsole;
@ -110,7 +110,7 @@ namespace console {
tty = fopen("/dev/tty", "w+");
if (tty != nullptr) {
out = tty;
fout = tty;
}
}
@ -126,7 +126,7 @@ namespace console {
// Restore settings on POSIX systems
if (!simple_io) {
if (tty != nullptr) {
out = stdout;
fout = stdout;
fclose(tty);
tty = nullptr;
}
@ -145,19 +145,19 @@ namespace console {
fflush(stdout);
switch(display) {
case reset:
fprintf(out, ANSI_COLOR_RESET);
fprintf(fout, ANSI_COLOR_RESET);
break;
case prompt:
fprintf(out, ANSI_COLOR_YELLOW);
fprintf(fout, ANSI_COLOR_YELLOW);
break;
case user_input:
fprintf(out, ANSI_BOLD ANSI_COLOR_GREEN);
fprintf(fout, ANSI_BOLD ANSI_COLOR_GREEN);
break;
case error:
fprintf(out, ANSI_BOLD ANSI_COLOR_RED);
fprintf(fout, ANSI_BOLD ANSI_COLOR_RED);
}
current_display = display;
fflush(out);
fflush(fout);
}
}
@ -233,7 +233,7 @@ namespace console {
return;
}
#endif
putc('\b', out);
putc('\b', fout);
}
static int estimateWidth(char32_t codepoint) {
@ -274,7 +274,7 @@ namespace console {
#else
// We can trust expectedWidth if we've got one
if (expectedWidth >= 0 || tty == nullptr) {
fwrite(utf8_codepoint, length, 1, out);
fwrite(utf8_codepoint, length, 1, fout);
return expectedWidth;
}
@ -311,7 +311,7 @@ namespace console {
pop_cursor();
put_codepoint(&ch, 1, 1);
#else
fprintf(out, "\b%c", ch);
fprintf(fout, "\b%c", ch);
#endif
}
@ -353,7 +353,7 @@ namespace console {
}
static bool readline_advanced(std::string & line, bool multiline_input) {
if (out != stdout) {
if (fout != stdout) {
fflush(stdout);
}
@ -364,7 +364,7 @@ namespace console {
char32_t input_char;
while (true) {
fflush(out); // Ensure all output is displayed before waiting for input
fflush(fout); // Ensure all output is displayed before waiting for input
input_char = getchar32();
if (input_char == '\r' || input_char == '\n') {
@ -432,7 +432,7 @@ namespace console {
line.pop_back();
if (last == '\\') {
line += '\n';
fputc('\n', out);
fputc('\n', fout);
has_more = !has_more;
} else {
// llama will just eat the single space, it won't act as a space
@ -447,11 +447,11 @@ namespace console {
has_more = false;
} else {
line += '\n';
fputc('\n', out);
fputc('\n', fout);
}
}
fflush(out);
fflush(fout);
return has_more;
}

View file

@ -338,16 +338,16 @@ public:
resume();
}
void set_prefix(bool prefix) {
void set_prefix(bool val) {
std::lock_guard<std::mutex> lock(mtx);
this->prefix = prefix;
prefix = val;
}
void set_timestamps(bool timestamps) {
void set_timestamps(bool val) {
std::lock_guard<std::mutex> lock(mtx);
this->timestamps = timestamps;
timestamps = val;
}
};