diff --git a/examples/gbnf-validator/gbnf-validator.cpp b/examples/gbnf-validator/gbnf-validator.cpp index a610e6a0b..04d1fd002 100644 --- a/examples/gbnf-validator/gbnf-validator.cpp +++ b/examples/gbnf-validator/gbnf-validator.cpp @@ -1,5 +1,6 @@ #include "unicode.h" #include "llama-grammar.h" +#include "log.h" #include #include @@ -47,7 +48,7 @@ static void print_error_message(const std::string & input_str, size_t error_pos, if (error_pos+1 < input_str.size()) { fprintf(stdout, "\033[0;31m%s", input_str.substr(error_pos+1).c_str()); } - fprintf(stdout, "\033[0m\n"); + fprintf(stdout, LOG_COL_DEFAULT "\n"); } } diff --git a/examples/lookahead/lookahead.cpp b/examples/lookahead/lookahead.cpp index 2f0898e62..60a97b974 100644 --- a/examples/lookahead/lookahead.cpp +++ b/examples/lookahead/lookahead.cpp @@ -295,7 +295,7 @@ int main(int argc, char ** argv) { LOG("%s", token_str.c_str()); } else { // print light cyan - LOG("\033[0;96m%s\033[0m", token_str.c_str()); + LOG("\033[0;96m%s" LOG_COL_DEFAULT, token_str.c_str()); } fflush(stdout); diff --git a/examples/lookup/lookup.cpp b/examples/lookup/lookup.cpp index dbd0444ec..54485b58d 100644 --- a/examples/lookup/lookup.cpp +++ b/examples/lookup/lookup.cpp @@ -160,7 +160,7 @@ int main(int argc, char ** argv){ if (params.use_color) { // color accepted draft token - LOG("\033[34m%s\033[0m", token_str.c_str()); + LOG(LOG_COL_BLUE "%s" LOG_COL_DEFAULT, token_str.c_str()); fflush(stdout); } continue; diff --git a/examples/main/main.cpp b/examples/main/main.cpp index e654d3542..fcff06945 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -647,7 +647,7 @@ int main(int argc, char ** argv) { LOG_DBG("n_past = %d\n", n_past); // Display total tokens alongside total time if (params.n_print > 0 && n_past % params.n_print == 0) { - LOG_DBG("\n\033[31mTokens consumed so far = %d / %d \033[0m\n", n_past, n_ctx); + LOG_DBG("\n" LOG_COL_RED "Tokens consumed so far = %d / %d " LOG_COL_DEFAULT "\n", n_past, n_ctx); } } diff --git a/examples/parallel/parallel.cpp b/examples/parallel/parallel.cpp index 7ef43d5e1..83216cd27 100644 --- a/examples/parallel/parallel.cpp +++ b/examples/parallel/parallel.cpp @@ -85,7 +85,7 @@ static void print_date_time() { strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", local_time); LOG_INF("\n"); - LOG_INF("\033[35mrun parameters as of %s\033[0m\n", buffer); + LOG_INF(LOG_COL_MAGENTA "run parameters as of %s" LOG_COL_DEFAULT "\n", buffer); LOG_INF("\n"); } @@ -139,11 +139,11 @@ int main(int argc, char ** argv) { // load the prompts from an external file if there are any if (params.prompt.empty()) { - LOG_INF("\033[32mNo new questions so proceed with build-in defaults.\033[0m\n"); + LOG_INF(LOG_COL_GREEN "No new questions so proceed with build-in defaults." LOG_COL_DEFAULT "\n"); } else { // Output each line of the input params.prompts vector and copy to k_prompts int index = 0; - LOG_INF("\033[32mNow printing the external prompt file %s\033[0m\n\n", params.prompt_file.c_str()); + LOG_INF(LOG_COL_GREEN "Now printing the external prompt file %s" LOG_COL_DEFAULT "\n\n", params.prompt_file.c_str()); std::vector prompts = split_string(params.prompt, '\n'); for (const auto& prompt : prompts) { @@ -273,7 +273,7 @@ int main(int argc, char ** argv) { client.n_decoded = 0; client.i_batch = batch.n_tokens - 1; - LOG_INF("\033[31mClient %3d, seq %4d, started decoding ...\033[0m\n", client.id, client.seq_id); + LOG_INF(LOG_COL_RED "Client %3d, seq %4d, started decoding ..." LOG_COL_DEFAULT "\n", client.id, client.seq_id); g_seq_id += 1; @@ -376,7 +376,7 @@ int main(int argc, char ** argv) { const auto t_main_end = ggml_time_us(); - LOG_INF("\033[31mClient %3d, seq %3d/%3d, prompt %4d t, response %4d t, time %5.2f s, speed %5.2f t/s, cache miss %d \033[0m \n\nInput: %s\n\033[35mResponse: %s\033[0m\n\n", + LOG_INF(LOG_COL_RED "Client %3d, seq %3d/%3d, prompt %4d t, response %4d t, time %5.2f s, speed %5.2f t/s, cache miss %d " LOG_COL_DEFAULT " \n\nInput: %s\n" LOG_COL_MAGENTA "Response: %s" LOG_COL_DEFAULT "\n\n", client.id, client.seq_id, n_seq, client.n_prompt, client.n_decoded, (t_main_end - client.t_start_prompt) / 1e6, (double) (client.n_prompt + client.n_decoded) / (t_main_end - client.t_start_prompt) * 1e6, @@ -403,8 +403,8 @@ int main(int argc, char ** argv) { if (params.prompt_file.empty()) { params.prompt_file = "used built-in defaults"; } - LOG_INF("External prompt file: \033[32m%s\033[0m\n", params.prompt_file.c_str()); - LOG_INF("Model and path used: \033[32m%s\033[0m\n\n", params.model.c_str()); + LOG_INF("External prompt file: " LOG_COL_GREEN "%s" LOG_COL_DEFAULT "\n", params.prompt_file.c_str()); + LOG_INF("Model and path used: " LOG_COL_GREEN "%s" LOG_COL_DEFAULT "\n\n", params.model.c_str()); LOG_INF("Total prompt tokens: %6d, speed: %5.2f t/s\n", n_total_prompt, (double) (n_total_prompt ) / (t_main_end - t_main_start) * 1e6); LOG_INF("Total gen tokens: %6d, speed: %5.2f t/s\n", n_total_gen, (double) (n_total_gen ) / (t_main_end - t_main_start) * 1e6); diff --git a/examples/run/linenoise.cpp/linenoise.cpp b/examples/run/linenoise.cpp/linenoise.cpp index a68f12a1a..6d0487081 100644 --- a/examples/run/linenoise.cpp/linenoise.cpp +++ b/examples/run/linenoise.cpp/linenoise.cpp @@ -104,6 +104,7 @@ */ # include "linenoise.h" +# include "log.h" # include # include @@ -527,7 +528,7 @@ static void refreshShowHints(std::string & ab, struct linenoiseState * l, int pl ab.append(seq); ab.append(hint, hintlen); if (color != -1 || bold != 0) - ab.append("\033[0m"); + ab.append(LOG_COL_DEFAULT); /* Call the function to free the hint returned. */ if (freeHintsCallback) freeHintsCallback(hint); diff --git a/examples/simple-chat/simple-chat.cpp b/examples/simple-chat/simple-chat.cpp index c5534cc13..51e849272 100644 --- a/examples/simple-chat/simple-chat.cpp +++ b/examples/simple-chat/simple-chat.cpp @@ -1,4 +1,5 @@ #include "llama.h" +#include "log.h" #include #include #include @@ -115,7 +116,7 @@ int main(int argc, char ** argv) { int n_ctx = llama_n_ctx(ctx); int n_ctx_used = llama_get_kv_cache_used_cells(ctx); if (n_ctx_used + batch.n_tokens > n_ctx) { - printf("\033[0m\n"); + printf(LOG_COL_DEFAULT "\n"); fprintf(stderr, "context size exceeded\n"); exit(0); } @@ -155,7 +156,7 @@ int main(int argc, char ** argv) { int prev_len = 0; while (true) { // get user input - printf("\033[32m> \033[0m"); + printf(LOG_COL_GREEN "> " LOG_COL_DEFAULT); std::string user; std::getline(std::cin, user); @@ -181,9 +182,9 @@ int main(int argc, char ** argv) { std::string prompt(formatted.begin() + prev_len, formatted.begin() + new_len); // generate a response - printf("\033[33m"); + printf(LOG_COL_YELLOW); std::string response = generate(prompt); - printf("\n\033[0m"); + printf("\n" LOG_COL_DEFAULT); // add the response to the messages messages.push_back({"assistant", strdup(response.c_str())}); diff --git a/examples/tts/tts.cpp b/examples/tts/tts.cpp index f78f76303..cd9d561ab 100644 --- a/examples/tts/tts.cpp +++ b/examples/tts/tts.cpp @@ -804,7 +804,7 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14 const int col = std::max(0, std::min((int) k_colors.size() - 1, (int) ((3*p)*float(k_colors.size())))); - LOG_CNT("%s%d%s", k_colors[col].c_str(), i, "\033[0m"); + LOG_CNT("%s%d%s", k_colors[col].c_str(), i, LOG_COL_DEFAULT); //LOG_CNT("%d", i); }