| 228 | } |
| 229 | |
| 230 | static int eval_message(mtmd_cli_context & ctx, common_chat_msg & msg) { |
| 231 | bool add_bos = ctx.chat_history.empty(); |
| 232 | auto formatted_chat = chat_add_and_format(ctx, msg); |
| 233 | LOG_DBG("formatted_chat.prompt: %s\n", formatted_chat.c_str()); |
| 234 | |
| 235 | mtmd_input_text text; |
| 236 | text.text = formatted_chat.c_str(); |
| 237 | text.add_special = add_bos; |
| 238 | text.parse_special = true; |
| 239 | |
| 240 | if (g_is_interrupted) return 0; |
| 241 | |
| 242 | mtmd::input_chunks chunks(mtmd_input_chunks_init()); |
| 243 | auto bitmaps_c_ptr = ctx.bitmaps.c_ptr(); |
| 244 | int32_t res = mtmd_tokenize(ctx.ctx_vision.get(), |
| 245 | chunks.ptr.get(), // output |
| 246 | &text, // text |
| 247 | bitmaps_c_ptr.data(), |
| 248 | bitmaps_c_ptr.size()); |
| 249 | if (res != 0) { |
| 250 | LOG_ERR("Unable to tokenize prompt, res = %d\n", res); |
| 251 | return 1; |
| 252 | } |
| 253 | |
| 254 | ctx.bitmaps.entries.clear(); |
| 255 | |
| 256 | llama_pos new_n_past; |
| 257 | if (mtmd_helper_eval_chunks(ctx.ctx_vision.get(), |
| 258 | ctx.lctx, // lctx |
| 259 | chunks.ptr.get(), // chunks |
| 260 | ctx.n_past, // n_past |
| 261 | 0, // seq_id |
| 262 | ctx.n_batch, // n_batch |
| 263 | true, // logits_last |
| 264 | &new_n_past)) { |
| 265 | LOG_ERR("Unable to eval prompt\n"); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | ctx.n_past = new_n_past; |
| 270 | |
| 271 | LOG("\n"); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | int main(int argc, char ** argv) { |
| 277 | ggml_time_init(); |
no test coverage detected