mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-02-05 16:10:42 +01:00
Name colors (#11573)
It's more descriptive, use #define's so we can use compile-time concatenations. Signed-off-by: Eric Curtin <ecurtin@redhat.com>
This commit is contained in:
parent
bfcce4d693
commit
84ec8a58f7
@ -14,16 +14,6 @@ void common_log_set_verbosity_thold(int verbosity) {
|
|||||||
common_log_verbosity_thold = verbosity;
|
common_log_verbosity_thold = verbosity;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_COL_DEFAULT "\033[0m"
|
|
||||||
#define LOG_COL_BOLD "\033[1m"
|
|
||||||
#define LOG_COL_RED "\033[31m"
|
|
||||||
#define LOG_COL_GREEN "\033[32m"
|
|
||||||
#define LOG_COL_YELLOW "\033[33m"
|
|
||||||
#define LOG_COL_BLUE "\033[34m"
|
|
||||||
#define LOG_COL_MAGENTA "\033[35m"
|
|
||||||
#define LOG_COL_CYAN "\033[36m"
|
|
||||||
#define LOG_COL_WHITE "\033[37m"
|
|
||||||
|
|
||||||
static int64_t t_us() {
|
static int64_t t_us() {
|
||||||
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
10
common/log.h
10
common/log.h
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
#include "ggml.h" // for ggml_log_level
|
#include "ggml.h" // for ggml_log_level
|
||||||
|
|
||||||
|
#define LOG_COL_DEFAULT "\033[0m"
|
||||||
|
#define LOG_COL_BOLD "\033[1m"
|
||||||
|
#define LOG_COL_RED "\033[31m"
|
||||||
|
#define LOG_COL_GREEN "\033[32m"
|
||||||
|
#define LOG_COL_YELLOW "\033[33m"
|
||||||
|
#define LOG_COL_BLUE "\033[34m"
|
||||||
|
#define LOG_COL_MAGENTA "\033[35m"
|
||||||
|
#define LOG_COL_CYAN "\033[36m"
|
||||||
|
#define LOG_COL_WHITE "\033[37m"
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
# define LOG_ATTRIBUTE_FORMAT(...)
|
# define LOG_ATTRIBUTE_FORMAT(...)
|
||||||
#elif defined(__MINGW32__)
|
#elif defined(__MINGW32__)
|
||||||
|
@ -24,15 +24,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "chat-template.hpp"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
#include "linenoise.cpp/linenoise.h"
|
#include "linenoise.cpp/linenoise.h"
|
||||||
#include "llama-cpp.h"
|
#include "llama-cpp.h"
|
||||||
#include "chat-template.hpp"
|
#include "log.h"
|
||||||
|
|
||||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
|
||||||
[[noreturn]] static void sigint_handler(int) {
|
[[noreturn]] static void sigint_handler(int) {
|
||||||
printf("\n\033[0m");
|
printf("\n" LOG_COL_DEFAULT);
|
||||||
exit(0); // not ideal, but it's the only way to guarantee exit in all cases
|
exit(0); // not ideal, but it's the only way to guarantee exit in all cases
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -890,7 +891,7 @@ static int check_context_size(const llama_context_ptr & ctx, const llama_batch &
|
|||||||
const int n_ctx = llama_n_ctx(ctx.get());
|
const int n_ctx = llama_n_ctx(ctx.get());
|
||||||
const int n_ctx_used = llama_get_kv_cache_used_cells(ctx.get());
|
const int n_ctx_used = llama_get_kv_cache_used_cells(ctx.get());
|
||||||
if (n_ctx_used + batch.n_tokens > n_ctx) {
|
if (n_ctx_used + batch.n_tokens > n_ctx) {
|
||||||
printf("\033[0m\n");
|
printf(LOG_COL_DEFAULT "\n");
|
||||||
printe("context size exceeded\n");
|
printe("context size exceeded\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -953,7 +954,7 @@ static int generate(LlamaData & llama_data, const std::string & prompt, std::str
|
|||||||
batch = llama_batch_get_one(&new_token_id, 1);
|
batch = llama_batch_get_one(&new_token_id, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\033[0m");
|
printf(LOG_COL_DEFAULT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,7 +963,7 @@ static int read_user_input(std::string & user_input) {
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
printf(
|
printf(
|
||||||
"\r%*s"
|
"\r%*s"
|
||||||
"\r\033[0m%s",
|
"\r" LOG_COL_DEFAULT "%s",
|
||||||
get_terminal_width(), " ", prompt_prefix);
|
get_terminal_width(), " ", prompt_prefix);
|
||||||
|
|
||||||
std::getline(std::cin, user_input);
|
std::getline(std::cin, user_input);
|
||||||
@ -999,7 +1000,7 @@ static int generate_response(LlamaData & llama_data, const std::string & prompt,
|
|||||||
const bool stdout_a_terminal) {
|
const bool stdout_a_terminal) {
|
||||||
// Set response color
|
// Set response color
|
||||||
if (stdout_a_terminal) {
|
if (stdout_a_terminal) {
|
||||||
printf("\033[33m");
|
printf(LOG_COL_YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generate(llama_data, prompt, response)) {
|
if (generate(llama_data, prompt, response)) {
|
||||||
@ -1008,7 +1009,7 @@ static int generate_response(LlamaData & llama_data, const std::string & prompt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End response with color reset and newline
|
// End response with color reset and newline
|
||||||
printf("\n%s", stdout_a_terminal ? "\033[0m" : "");
|
printf("\n%s", stdout_a_terminal ? LOG_COL_DEFAULT : "");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user