MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / insert

Method insert

src/common/AutoModel/modeling_qwen2.cpp:56–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56bool 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
82std::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);

Callers 1

generate_with_promptMethod · 0.95

Calls 8

apply_chat_templateMethod · 0.95
push_backMethod · 0.80
encodeMethod · 0.80
_shared_insertMethod · 0.80
startMethod · 0.45
emptyMethod · 0.45
stopMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected