| 639 | } |
| 640 | |
| 641 | llama_tokens tokenize_mixed(const llama_vocab * vocab, const json & json_prompt, bool add_special, bool parse_special) { |
| 642 | // If `add_bos` is true, we only add BOS, when json_prompt is a string, |
| 643 | // or the first element of the json_prompt array is a string. |
| 644 | llama_tokens prompt_tokens; |
| 645 | |
| 646 | if (json_prompt.is_array()) { |
| 647 | bool first = true; |
| 648 | for (const auto & p : json_prompt) { |
| 649 | if (p.is_string()) { |
| 650 | auto s = p.template get<std::string>(); |
| 651 | |
| 652 | llama_tokens p; |
| 653 | if (first) { |
| 654 | p = common_tokenize(vocab, s, add_special, parse_special); |
| 655 | first = false; |
| 656 | } else { |
| 657 | p = common_tokenize(vocab, s, false, parse_special); |
| 658 | } |
| 659 | |
| 660 | prompt_tokens.insert(prompt_tokens.end(), p.begin(), p.end()); |
| 661 | } else { |
| 662 | if (first) { |
| 663 | first = false; |
| 664 | } |
| 665 | |
| 666 | prompt_tokens.push_back(p.template get<llama_token>()); |
| 667 | } |
| 668 | } |
| 669 | } else { |
| 670 | auto s = json_prompt.template get<std::string>(); |
| 671 | prompt_tokens = common_tokenize(vocab, s, add_special, parse_special); |
| 672 | } |
| 673 | |
| 674 | return prompt_tokens; |
| 675 | } |
| 676 | |
| 677 | size_t validate_utf8(const std::string& text) { |
| 678 | size_t len = text.size(); |
no test coverage detected