| 1196 | } |
| 1197 | |
| 1198 | static std::string llama_token_to_piece(const struct llama_context * ctx, llama_token token) { |
| 1199 | std::vector<char> result(8, 0); |
| 1200 | const int n_tokens = llama_token_to_piece(llama_get_model(ctx), token, result.data(), result.size()); |
| 1201 | if (n_tokens < 0) { |
| 1202 | result.resize(-n_tokens); |
| 1203 | int check = llama_token_to_piece(llama_get_model(ctx), token, result.data(), result.size()); |
| 1204 | GGML_ASSERT(check == -n_tokens); |
| 1205 | } |
| 1206 | else { |
| 1207 | result.resize(n_tokens); |
| 1208 | } |
| 1209 | |
| 1210 | return std::string(result.data(), result.size()); |
| 1211 | } |
| 1212 | |
| 1213 | // |
| 1214 | // globals |