| 88 | } |
| 89 | |
| 90 | bool Phi4::insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input, std::function<bool()> is_cancelled) { |
| 91 | // preprocess |
| 92 | this->profiler_list[TKOEN_ENCODE_TIME].start(); |
| 93 | std::string templated_text; |
| 94 | if (input.messages.empty() && input.prompt.empty()) { |
| 95 | header_print("WARNING", "No messages or prompt provided"); |
| 96 | return false; |
| 97 | } |
| 98 | if (!input.messages.empty()) { // already a formated messages, usually from REST API |
| 99 | templated_text = this->apply_chat_template(input.messages); |
| 100 | } |
| 101 | else if (!input.prompt.empty()) { // a pure text, usually from the cli |
| 102 | nlohmann::ordered_json messages; |
| 103 | |
| 104 | messages.push_back({ {"role", "user"}, {"content", input.prompt} }); |
| 105 | templated_text = this->apply_chat_template(messages); |
| 106 | } |
| 107 | |
| 108 | std::vector<int> tokens = this->tokenizer->encode(templated_text); |
| 109 | this->profiler_list[TKOEN_ENCODE_TIME].stop(tokens.size()); |
| 110 | // hardware |
| 111 | |
| 112 | return this->_shared_insert(meta_info, tokens, is_cancelled); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | std::string Phi4::generate(chat_meta_info_t& meta_info, int length_limit, std::ostream& os, std::function<bool()> is_cancelled) { |
no test coverage detected