-
Notifications
You must be signed in to change notification settings - Fork 13.7k
server : add handle_slot_type lambda #11535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c5825e7
7c34af4
2d2d076
6cc2956
0e09ec8
c6f6579
bfc342c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3665,7 +3665,8 @@ int main(int argc, char ** argv) { | |
| res.status = 200; // HTTP OK | ||
| }; | ||
|
|
||
| const auto handle_slots_save = [&ctx_server, &res_error, &res_ok, ¶ms](const httplib::Request & req, httplib::Response & res, int id_slot) { | ||
| const auto handle_slot_type = [&ctx_server, &res_error, &res_ok, ¶ms](const httplib::Request & req, | ||
| httplib::Response & res, int id_slot, server_task_type type) { | ||
| json request_data = json::parse(req.body); | ||
| std::string filename = request_data.at("filename"); | ||
| if (!fs_validate_filename(filename)) { | ||
|
|
@@ -3674,7 +3675,7 @@ int main(int argc, char ** argv) { | |
| } | ||
| std::string filepath = params.slot_save_path + filename; | ||
|
|
||
| server_task task(SERVER_TASK_TYPE_SLOT_SAVE); | ||
| server_task task(type); | ||
| task.id = ctx_server.queue_tasks.get_new_id(); | ||
| task.slot_action.slot_id = id_slot; | ||
| task.slot_action.filename = filename; | ||
|
|
@@ -3691,37 +3692,18 @@ int main(int argc, char ** argv) { | |
| return; | ||
| } | ||
|
|
||
| if (type == SERVER_TASK_TYPE_SLOT_SAVE) { | ||
| GGML_ASSERT(dynamic_cast<server_task_result_slot_save_load*>(result.get()) != nullptr); | ||
|
||
| } | ||
| res_ok(res, result->to_json()); | ||
| }; | ||
|
|
||
| const auto handle_slots_restore = [&ctx_server, &res_error, &res_ok, ¶ms](const httplib::Request & req, httplib::Response & res, int id_slot) { | ||
| json request_data = json::parse(req.body); | ||
| std::string filename = request_data.at("filename"); | ||
| if (!fs_validate_filename(filename)) { | ||
| res_error(res, format_error_response("Invalid filename", ERROR_TYPE_INVALID_REQUEST)); | ||
| return; | ||
| } | ||
| std::string filepath = params.slot_save_path + filename; | ||
|
|
||
| server_task task(SERVER_TASK_TYPE_SLOT_RESTORE); | ||
| task.id = ctx_server.queue_tasks.get_new_id(); | ||
| task.slot_action.slot_id = id_slot; | ||
| task.slot_action.filename = filename; | ||
| task.slot_action.filepath = filepath; | ||
|
|
||
| ctx_server.queue_results.add_waiting_task_id(task.id); | ||
| ctx_server.queue_tasks.post(task); | ||
|
|
||
| server_task_result_ptr result = ctx_server.queue_results.recv(task.id); | ||
| ctx_server.queue_results.remove_waiting_task_id(task.id); | ||
|
|
||
| if (result->is_error()) { | ||
| res_error(res, result->to_json()); | ||
| return; | ||
| } | ||
| const auto handle_slots_save = [&handle_slot_type](const httplib::Request & req, httplib::Response & res, int id_slot) { | ||
| handle_slot_type(req, res, id_slot, SERVER_TASK_TYPE_SLOT_SAVE); | ||
| }; | ||
|
|
||
| GGML_ASSERT(dynamic_cast<server_task_result_slot_save_load*>(result.get()) != nullptr); | ||
| res_ok(res, result->to_json()); | ||
| const auto handle_slots_restore = [&handle_slot_type](const httplib::Request & req, httplib::Response & res, int id_slot) { | ||
| handle_slot_type(req, res, id_slot, SERVER_TASK_TYPE_SLOT_RESTORE); | ||
| }; | ||
|
|
||
| const auto handle_slots_erase = [&ctx_server, &res_error, &res_ok](const httplib::Request & /* req */, httplib::Response & res, int id_slot) { | ||
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.