MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / init_routes

Method init_routes

subprojects/llama.cpp/tools/server/server-models.cpp:793–913  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

791}
792
793void server_models_routes::init_routes() {
794 this->get_router_props = [this](const server_http_req & req) {
795 std::string name = req.get_param("model");
796 if (name.empty()) {
797 // main instance
798 auto res = std::make_unique<server_http_res>();
799 res_ok(res, {
800 // TODO: add support for this on web UI
801 {"role", "router"},
802 {"max_instances", 4}, // dummy value for testing
803 // this is a dummy response to make sure webui doesn't break
804 {"model_alias", "llama-server"},
805 {"model_path", "none"},
806 {"default_generation_settings", {
807 {"params", json{}},
808 {"n_ctx", 0},
809 }},
810 {"webui_settings", webui_settings},
811 });
812 return res;
813 }
814 return proxy_get(req);
815 };
816
817 this->proxy_get = [this](const server_http_req & req) {
818 std::string method = "GET";
819 std::string name = req.get_param("model");
820 bool autoload = is_autoload(params, req);
821 auto error_res = std::make_unique<server_http_res>();
822 if (!router_validate_model(name, models, autoload, error_res)) {
823 return error_res;
824 }
825 return models.proxy_request(req, method, name, false);
826 };
827
828 this->proxy_post = [this](const server_http_req & req) {
829 std::string method = "POST";
830 json body = json::parse(req.body);
831 std::string name = json_value(body, "model", std::string());
832 bool autoload = is_autoload(params, req);
833 auto error_res = std::make_unique<server_http_res>();
834 if (!router_validate_model(name, models, autoload, error_res)) {
835 return error_res;
836 }
837 return models.proxy_request(req, method, name, true); // update last usage for POST request only
838 };
839
840 this->post_router_models_load = [this](const server_http_req & req) {
841 auto res = std::make_unique<server_http_res>();
842 json body = json::parse(req.body);
843 std::string name = json_value(body, "model", std::string());
844 auto model = models.get_meta(name);
845 if (!model.has_value()) {
846 res_err(res, format_error_response("model is not found", ERROR_TYPE_NOT_FOUND));
847 return res;
848 }
849 if (model->status == SERVER_MODEL_STATUS_LOADED) {
850 res_err(res, format_error_response("model is already loaded", ERROR_TYPE_INVALID_REQUEST));

Callers

nothing calls this directly

Calls 15

res_okFunction · 0.85
is_autoloadFunction · 0.85
router_validate_modelFunction · 0.85
parseFunction · 0.85
json_valueFunction · 0.85
stringClass · 0.85
res_errFunction · 0.85
format_error_responseFunction · 0.85
unset_reserved_argsFunction · 0.85
get_paramMethod · 0.80
proxy_requestMethod · 0.80

Tested by

no test coverage detected