| 197 | } |
| 198 | |
| 199 | static 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 | |
| 248 | int main(int argc, char ** argv) { |
| 249 | ggml_time_init(); |
no test coverage detected