MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / eval_message

Function eval_message

smallthinker/tools/mtmd/mtmd-cli.cpp:199–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199static int eval_message(mtmd_cli_context & ctx, common_chat_msg & msg, bool add_bos = false) {
200 common_chat_templates_inputs tmpl_inputs;
201 tmpl_inputs.messages = {msg};
202 tmpl_inputs.add_generation_prompt = true;
203 tmpl_inputs.use_jinja = false; // jinja is buggy here
204 auto formatted_chat = common_chat_templates_apply(ctx.tmpls.get(), tmpl_inputs);
205 LOG_DBG("formatted_chat.prompt: %s\n", formatted_chat.prompt.c_str());
206
207 mtmd_input_text text;
208 text.text = formatted_chat.prompt.c_str();
209 text.add_special = add_bos;
210 text.parse_special = true;
211
212 if (g_is_interrupted) return 0;
213
214 mtmd::input_chunks chunks(mtmd_input_chunks_init());
215 auto bitmaps_c_ptr = ctx.bitmaps.c_ptr();
216 int32_t res = mtmd_tokenize(ctx.ctx_vision.get(),
217 chunks.ptr.get(), // output
218 &text, // text
219 bitmaps_c_ptr.data(),
220 bitmaps_c_ptr.size());
221 if (res != 0) {
222 LOG_ERR("Unable to tokenize prompt, res = %d\n", res);
223 return 1;
224 }
225
226 ctx.bitmaps.entries.clear();
227
228 llama_pos new_n_past;
229 if (mtmd_helper_eval_chunks(ctx.ctx_vision.get(),
230 ctx.lctx, // lctx
231 chunks.ptr.get(), // chunks
232 ctx.n_past, // n_past
233 0, // seq_id
234 ctx.n_batch, // n_batch
235 true, // logits_last
236 &new_n_past)) {
237 LOG_ERR("Unable to eval prompt\n");
238 return 1;
239 }
240
241 ctx.n_past = new_n_past;
242
243 LOG("\n");
244
245 return 0;
246}
247
248int main(int argc, char ** argv) {
249 ggml_time_init();

Callers 1

mainFunction · 0.85

Calls 10

mtmd_input_chunks_initFunction · 0.85
mtmd_tokenizeFunction · 0.85
mtmd_helper_eval_chunksFunction · 0.85
c_ptrMethod · 0.80
getMethod · 0.45
c_strMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected