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

Method insert

src/common/AutoModel/modeling_qwen2vl.cpp:57–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57bool Qwen2VL::insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input, std::function<bool()> is_cancelled) {
58 // preprocess
59 constexpr int image_soft_token_id = 151655;
60 this->profiler_list[TKOEN_ENCODE_TIME].start();
61 std::string templated_text;
62 if (input.messages.empty() && input.prompt.empty()) {
63 header_print_r("WARNING", "No messages or prompt provided");
64 return false;
65 }
66
67 constexpr bool DEBUG_IMAGE_PREPROCESS = false;
68 qwen2vl_image_payload_t image_payload;
69 image_payload.num_images = 0;
70 if (input.images.size() > 0) {
71
72
73 // header_print("info", "Processing images...");
74
75 // time_utils::time_point preprocess_start = time_utils::now();
76 for(const auto& img_str : input.images){
77 qwen2vl_image_t image = this->load_image(img_str);
78
79 preprocess_image(image, image_payload._data__processed);
80
81 // Push the image AFTER preprocessing so grid_h and grid_w are set
82 image_payload.images.push_back(image);
83 image_payload.num_images++;
84 }
85 }
86 try {
87 if (!input.messages.empty()) { // already a formated messages, usually from REST API
88 json qwenvl_message = json::array();
89 std::vector<const std::string*> pending_images;
90 int total_images = 0;
91 for (const auto& item : input.messages) {
92 if (!item.contains("images")) {
93 qwenvl_message.push_back(item);
94 continue;
95 }
96
97 json newContent = json::array();
98 for (const auto& img : item["images"]) {
99 if (img.is_string()) {
100 pending_images.push_back(&img.get_ref<const std::string&>());
101 total_images++;
102 }
103 newContent.push_back({
104 {"type", "image"}
105 });
106 }
107 newContent.push_back({
108 {"type", "text"},
109 {"text", item["content"]}
110 });
111
112 json newItem = {
113 {"role", item["role"]},
114 {"content", newContent}

Callers 1

generate_with_promptMethod · 0.95

Calls 15

load_imageMethod · 0.95
apply_chat_templateMethod · 0.95
load_image_base64Method · 0.95
push_backMethod · 0.80
is_stringMethod · 0.80
encodeMethod · 0.80
eraseMethod · 0.80
clearMethod · 0.80
_shared_insertMethod · 0.80
to_stringFunction · 0.50
startMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected