| 446 | } |
| 447 | |
| 448 | std::string common_sampler_prev_str(common_sampler * gsmpl, llama_context * ctx_main, int n) { |
| 449 | n = std::min(n, (int) gsmpl->prev.size()); |
| 450 | |
| 451 | if (n <= 0) { |
| 452 | return ""; |
| 453 | } |
| 454 | |
| 455 | std::string result; |
| 456 | result.reserve(8*n); // 8 is the average length of a token [citation needed], TODO: compute this from the vocab |
| 457 | |
| 458 | for (int i = n - 1; i >= 0; i--) { |
| 459 | const llama_token id = gsmpl->prev.rat(i); |
| 460 | |
| 461 | GGML_ASSERT(id != LLAMA_TOKEN_NULL && "null token in the sampling history - should not happen"); |
| 462 | |
| 463 | result += common_token_to_piece(ctx_main, id); |
| 464 | } |
| 465 | |
| 466 | return result; |
| 467 | } |
| 468 | |
| 469 | char common_sampler_type_to_chr(enum common_sampler_type cnstr) { |
| 470 | switch (cnstr) { |
no test coverage detected