| 1366 | } |
| 1367 | |
| 1368 | void process_tasks() |
| 1369 | { |
| 1370 | std::lock_guard<std::mutex> lock(mutex_tasks); |
| 1371 | while (!queue_tasks.empty()) |
| 1372 | { |
| 1373 | task_server task = queue_tasks.front(); |
| 1374 | queue_tasks.erase(queue_tasks.begin()); |
| 1375 | switch (task.type) |
| 1376 | { |
| 1377 | case COMPLETION_TASK: { |
| 1378 | llama_client_slot *slot = get_slot(json_value(task.data, "slot_id", -1)); |
| 1379 | if (slot == nullptr) |
| 1380 | { |
| 1381 | LOG_TEE("slot unavailable\n"); |
| 1382 | // send error result |
| 1383 | send_error(task.id, "slot unavailable"); |
| 1384 | return; |
| 1385 | } |
| 1386 | |
| 1387 | if (task.data.contains("system_prompt")) |
| 1388 | { |
| 1389 | process_system_prompt_data(task.data["system_prompt"]); |
| 1390 | } |
| 1391 | |
| 1392 | slot->reset(); |
| 1393 | |
| 1394 | slot->infill = task.infill_mode; |
| 1395 | slot->embedding = task.embedding_mode; |
| 1396 | slot->task_id = task.id; |
| 1397 | |
| 1398 | if (!launch_slot_with_data(slot, task.data)) |
| 1399 | { |
| 1400 | // send error result |
| 1401 | send_error(task.id, "internal_error"); |
| 1402 | break; |
| 1403 | } |
| 1404 | } break; |
| 1405 | case CANCEL_TASK: { // release slot linked with the task id |
| 1406 | for (auto & slot : slots) |
| 1407 | { |
| 1408 | if (slot.task_id == task.target_id) |
| 1409 | { |
| 1410 | slot.release(); |
| 1411 | break; |
| 1412 | } |
| 1413 | } |
| 1414 | } break; |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | bool update_slots() { |
| 1420 | // attend tasks |
nothing calls this directly
no test coverage detected