MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / tokenize

Method tokenize

examples/server/server.cpp:607–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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();

Callers 1

mainFunction · 0.45

Calls 5

llama_tokenizeFunction · 0.50
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected