Spaces:
Sleeping
Sleeping
Dmitry Beresnev commited on
Commit ·
8ef326a
1
Parent(s): a97386f
add new endpoint to cancel all processing prompts
Browse files144 unmodified lines145146147148149150253 unmodified lines404405406407408409144 unmodified linesreturn true;}std::optional<WorkerInfo> active_worker() {std::lock_guard<std::mutex> lock(_mu);if (_active && is_alive(_active->pid)) return _active;253 unmodified linesreturn json_response(http::status::ok, state);}if (path == "/v1/chat/completions" && req.method() == http::verb::post) {auto worker = manager.active_worker();if (!worker) {144 unmodified lines145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198253 unmodified lines452453454455456457458459460461462463464465466467468469470471472473474144 unmodified linesreturn true;}bool restart_active(std::string &error) {std::optional<WorkerInfo> old_worker;std::string model;{std::lock_guard<std::mutex> lock(_mu);if (_switch_in_progress) {error = "Switch already in progress";return false;}if (!_active || !is_alive(_active->pid)) {error = "No active model";return false;}_switch_in_progress = true;old_worker = _active;model = _active->model;}shutdown_worker(old_worker->pid);int port = allocate_port();pid_t pid = spawn_worker(model, port);if (pid <= 0) {std::lock_guard<std::mutex> lock(_mu);_active = std::nullopt;_switch_in_progress = false;error = "Failed to start worker process";return false;}if (!wait_until_ready(pid, port, _switch_timeout_sec)) {shutdown_worker(pid);std::lock_guard<std::mutex> lock(_mu);_active = std::nullopt;_switch_in_progress = false;error = "New model did not become ready in time";return false;}WorkerInfo new_worker{model, port, pid, now_utc_iso()};{std::lock_guard<std::mutex> lock(_mu);_active = new_worker;_switch_in_progress = false;}return true;}std::optional<WorkerInfo> active_worker() {std::lock_guard<std::mutex> lock(_mu);if (_active && is_alive(_active->pid)) return _active;253 unmodified linesreturn json_response(http::status::ok, state);}if (path == "/stop" && req.method() == http::verb::post) {std::string err;bool ok = manager.restart_active(err);if (!ok) {http::status status = http::status::internal_server_error;if (err == "Switch already in progress") {status = http::status::conflict;} else if (err == "No active model") {status = http::status::service_unavailable;}return json_response(status, {{"status", "error"}, {"error", err}});}auto state = manager.models_view();state["message"] = "Stopped in-flight prompts and restarted model";return json_response(http::status::ok, state);}if (path == "/v1/chat/completions" && req.method() == http::verb::post) {auto worker = manager.active_worker();if (!worker) {
cpp/llm_manager.cpp+65