| 1053 | } |
| 1054 | |
| 1055 | bool process_images(llama_client_slot &slot) const |
| 1056 | { |
| 1057 | for (slot_image &img : slot.images) |
| 1058 | { |
| 1059 | if (!img.request_encode_image) |
| 1060 | { |
| 1061 | continue; |
| 1062 | } |
| 1063 | clip_image_f32 img_res; |
| 1064 | if (!clip_image_preprocess(clp_ctx, &img.img_data, &img_res, /*pad2square =*/ true)) |
| 1065 | { |
| 1066 | LOG_TEE("Error processing the given image"); |
| 1067 | clip_free(clp_ctx); |
| 1068 | return false; |
| 1069 | } |
| 1070 | img.image_tokens = clip_n_patches(clp_ctx); |
| 1071 | img.image_embedding = (float *)malloc(clip_embd_nbytes(clp_ctx)); |
| 1072 | if (!img.image_embedding) |
| 1073 | { |
| 1074 | LOG_TEE("Unable to allocate memory for image embeddings\n"); |
| 1075 | clip_free(clp_ctx); |
| 1076 | return false; |
| 1077 | } |
| 1078 | LOG_TEE("slot %i - encoding image [id: %i]\n", slot.id, img.id); |
| 1079 | if (!clip_image_encode(clp_ctx, params.n_threads, &img_res, img.image_embedding)) |
| 1080 | { |
| 1081 | LOG_TEE("Unable to encode image\n"); |
| 1082 | return false; |
| 1083 | } |
| 1084 | img.request_encode_image = false; |
| 1085 | } |
| 1086 | |
| 1087 | return slot.images.size() > 0; |
| 1088 | } |
| 1089 | |
| 1090 | void send_error(int id, std::string error) |
| 1091 | { |
nothing calls this directly
no test coverage detected