| 605 | } |
| 606 | |
| 607 | std::vector<llama_token> tokenize(const json & json_prompt, bool add_bos) const |
| 608 | { |
| 609 | // If `add_bos` is true, we only add BOS, when json_prompt is a string, |
| 610 | // or the first element of the json_prompt array is a string. |
| 611 | std::vector<llama_token> prompt_tokens; |
| 612 | |
| 613 | if (json_prompt.is_array()) |
| 614 | { |
| 615 | bool first = true; |
| 616 | for (const auto& p : json_prompt) |
| 617 | { |
| 618 | if (p.is_string()) |
| 619 | { |
| 620 | auto s = p.template get<std::string>(); |
| 621 | std::vector<llama_token> p; |
| 622 | if (first) |
| 623 | { |
| 624 | p = ::llama_tokenize(ctx, s, add_bos); |
| 625 | first = false; |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | p = ::llama_tokenize(ctx, s, false); |
| 630 | } |
| 631 | prompt_tokens.insert(prompt_tokens.end(), p.begin(), p.end()); |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | if (first) |
| 636 | { |
| 637 | first = false; |
| 638 | } |
| 639 | prompt_tokens.push_back(p.template get<llama_token>()); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | else |
| 644 | { |
| 645 | auto s = json_prompt.template get<std::string>(); |
| 646 | prompt_tokens = ::llama_tokenize(ctx, s, add_bos); |
| 647 | } |
| 648 | |
| 649 | return prompt_tokens; |
| 650 | } |
| 651 | |
| 652 | llama_client_slot* get_slot(int id) { |
| 653 | int64_t t_last = ggml_time_us(); |