@@ -154,6 +154,15 @@ void sigint_handler(int signo) {
154154}
155155#endif
156156
157+ void print_color_for_prob (double prob) {
158+ int p = prob*0xFF ;
159+ printf (" \x1b [48;2;%d;%d;%dm" , 0xFF -p, (0xFF -p)/10 + 10 , p/10 );
160+ }
161+
162+ void print_color_reset () {
163+ printf (" \x1b [0m" );
164+ }
165+
157166int main (int argc, char ** argv) {
158167 // has to be called once at the start of the program to init ggml stuff
159168 ggml_time_init ();
@@ -335,6 +344,7 @@ int main(int argc, char ** argv) {
335344
336345 n_past += embd.size ();
337346 embd.clear ();
347+ double prob = 0.0 ;
338348
339349 if ((int ) embd_inp.size () <= input_consumed) {
340350 // out of user input, sample next token
@@ -356,7 +366,7 @@ int main(int argc, char ** argv) {
356366 logits[llama_token_eos ()] = 0 ;
357367 }
358368
359- id = llama_sample_top_p_top_k (ctx, last_n_tokens.data (), last_n_tokens.size (), top_k, top_p, temp, repeat_penalty);
369+ id = llama_sample_top_p_top_k (ctx, last_n_tokens.data (), last_n_tokens.size (), top_k, top_p, temp, repeat_penalty, &prob );
360370
361371 last_n_tokens.erase (last_n_tokens.begin ());
362372 last_n_tokens.push_back (id);
@@ -393,13 +403,15 @@ int main(int argc, char ** argv) {
393403 }
394404 }
395405
406+ print_color_for_prob (prob);
396407 // display text
397408 if (!input_noecho) {
398409 for (auto id : embd) {
399410 printf (" %s" , llama_token_to_str (ctx, id));
400411 }
401412 fflush (stdout);
402413 }
414+ print_color_reset ();
403415 // reset color to default if we there is no pending user input
404416 if (!input_noecho && (int )embd_inp.size () == input_consumed) {
405417 set_console_state (CONSOLE_STATE_DEFAULT);
0 commit comments