| 205 | } |
| 206 | |
| 207 | static void process_prompt(struct llava_context * ctx_llava, struct llava_image_embed * image_embed, gpt_params * params, const std::string & prompt) { |
| 208 | int n_past = 0; |
| 209 | |
| 210 | const int max_tgt_len = params->n_predict < 0 ? 256 : params->n_predict; |
| 211 | |
| 212 | // llava chat format is "<system_prompt>\nUSER:<image_embeddings>\n<textual_prompt>\nASSISTANT:" |
| 213 | eval_string(ctx_llava->ctx_llama, "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.\nUSER:", params->n_batch, &n_past, true); |
| 214 | llava_eval_image_embed(ctx_llava->ctx_llama, image_embed, params->n_batch, &n_past); |
| 215 | eval_string(ctx_llava->ctx_llama, (prompt + "\nASSISTANT:").c_str(), params->n_batch, &n_past, false); |
| 216 | |
| 217 | // generate the response |
| 218 | |
| 219 | printf("\n"); |
| 220 | |
| 221 | for (int i = 0; i < max_tgt_len; i++) { |
| 222 | const char * tmp = sample(ctx_llava->ctx_llama, *params, &n_past); |
| 223 | if (strcmp(tmp, "</s>") == 0) break; |
| 224 | |
| 225 | printf("%s", tmp); |
| 226 | fflush(stdout); |
| 227 | } |
| 228 | |
| 229 | printf("\n"); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static struct llava_context * llava_init(gpt_params * params) { |
no test coverage detected