Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 6 additions & 41 deletions examples/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,44 +649,6 @@ void parse_args(int argc, const char** argv, SDParams& params) {
params.ctxParams.n_threads = sd_get_num_physical_cores();
}

if (params.lastRequest.prompt.length() == 0) {
fprintf(stderr, "error: the following arguments are required: prompt\n");
print_usage(argc, argv, options);
exit(1);
}

if (params.ctxParams.model_path.length() == 0 && params.ctxParams.diffusion_model_path.length() == 0) {
fprintf(stderr, "error: the following arguments are required: model_path/diffusion_model\n");
print_usage(argc, argv, options);
exit(1);
}

if (params.output_path.length() == 0) {
fprintf(stderr, "error: the following arguments are required: output_path\n");
print_usage(argc, argv, options);
exit(1);
}

if (params.lastRequest.height <= 0) {
fprintf(stderr, "error: the height must be greater than 0\n");
exit(1);
}

if (params.lastRequest.width <= 0) {
fprintf(stderr, "error: the width must be greater than 0\n");
exit(1);
}

if (params.lastRequest.sample_params.sample_steps <= 0) {
fprintf(stderr, "error: the sample_steps must be greater than 0\n");
exit(1);
}

if (params.lastRequest.strength < 0.f || params.lastRequest.strength > 1.f) {
fprintf(stderr, "error: can only work with strength in [0.0, 1.0]\n");
exit(1);
}

if (params.lastRequest.seed < 0) {
srand((int)time(nullptr));
params.lastRequest.seed = rand();
Expand Down Expand Up @@ -2617,9 +2579,12 @@ void start_server(SDParams& params) {
if (g_task_results.find(task_id) != g_task_results.end()) {
json result = g_task_results[task_id];
res.set_content(result.dump(), "application/json");
// Erase data after sending
result["data"] = json::array();
g_task_results[task_id] = result;

if (g_task_results[task_id]["status"] == "Completed" ||
g_task_results[task_id]["status"] == "Failed") {
// Remove completed or failed tasks from the results map to free memory
g_task_results.erase(task_id);
}
} else {
res.set_content("Cannot find task " + task_id + " in queue", "text/plain");
res.status = 404;
Expand Down