| 1044 | } |
| 1045 | |
| 1046 | std::string llama_token_to_piece(const struct llama_context * ctx, llama_token token) { |
| 1047 | std::vector<char> result(8, 0); |
| 1048 | const int n_tokens = llama_token_to_piece(llama_get_model(ctx), token, result.data(), result.size()); |
| 1049 | if (n_tokens < 0) { |
| 1050 | result.resize(-n_tokens); |
| 1051 | int check = llama_token_to_piece(llama_get_model(ctx), token, result.data(), result.size()); |
| 1052 | GGML_ASSERT(check == -n_tokens); |
| 1053 | } else { |
| 1054 | result.resize(n_tokens); |
| 1055 | } |
| 1056 | |
| 1057 | return std::string(result.data(), result.size()); |
| 1058 | } |
| 1059 | |
| 1060 | std::string llama_detokenize_spm(llama_context * ctx, const std::vector<llama_token> & tokens) { |
| 1061 | const llama_token bos_id = llama_token_bos(llama_get_model(ctx)); |
no test coverage detected