| 54 | } |
| 55 | |
| 56 | bool Qwen2::insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input, std::function<bool()> is_cancelled) { |
| 57 | // preprocess |
| 58 | this->profiler_list[TKOEN_ENCODE_TIME].start(); |
| 59 | std::string templated_text; |
| 60 | if (input.messages.empty() && input.prompt.empty()) { |
| 61 | header_print("WARNING", "No messages or prompt provided"); |
| 62 | return false; |
| 63 | } |
| 64 | if (!input.messages.empty()) { // already a formated messages, usually from REST API |
| 65 | templated_text = this->apply_chat_template(input.messages); |
| 66 | } |
| 67 | else if (!input.prompt.empty()) { // a pure text, usually from the cli |
| 68 | nlohmann::ordered_json messages; |
| 69 | |
| 70 | messages.push_back({ {"role", "user"}, {"content", input.prompt} }); |
| 71 | templated_text = this->apply_chat_template(messages); |
| 72 | } |
| 73 | |
| 74 | std::vector<int> tokens = this->tokenizer->encode(templated_text); |
| 75 | |
| 76 | this->profiler_list[TKOEN_ENCODE_TIME].stop(tokens.size()); |
| 77 | // hardware |
| 78 | |
| 79 | return this->_shared_insert(meta_info, tokens, is_cancelled); |
| 80 | } |
| 81 | |
| 82 | std::string Qwen2::generate(chat_meta_info_t& meta_info, int length_limit, std::ostream& os, std::function<bool()> is_cancelled) { |
| 83 | return this->_shared_generate(meta_info, length_limit, os, is_cancelled); |
no test coverage detected