| 10733 | } |
| 10734 | |
| 10735 | int llama_tokenize( |
| 10736 | const struct llama_model * model, |
| 10737 | const char * text, |
| 10738 | int text_len, |
| 10739 | llama_token * tokens, |
| 10740 | int n_max_tokens, |
| 10741 | bool add_bos, |
| 10742 | bool special) { |
| 10743 | auto res = llama_tokenize_internal(model->vocab, std::string(text, text_len), add_bos, special); |
| 10744 | |
| 10745 | if (n_max_tokens < (int) res.size()) { |
| 10746 | // LLAMA_LOG_ERROR("%s: too many tokens\n", __func__); |
| 10747 | return -((int) res.size()); |
| 10748 | } |
| 10749 | |
| 10750 | for (size_t i = 0; i < res.size(); i++) { |
| 10751 | tokens[i] = res[i]; |
| 10752 | } |
| 10753 | |
| 10754 | return res.size(); |
| 10755 | } |
| 10756 | |
| 10757 | static std::string llama_decode_text(const std::string & text) { |
| 10758 | std::string decoded_text; |