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