MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / process_tasks

Method process_tasks

examples/server/server.cpp:1368–1417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

json_valueFunction · 0.70
emptyMethod · 0.45
beginMethod · 0.45
resetMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected