Repository: ggerganov/llama.cpp
File: tools/server/server.cpp (C++)

Code before:
            params.reasoning_format,
            ctx_server.chat_templates.get(),
            ctx_server.mctx,
            files);
        res_ok(res, {{ "prompt", std::move(data.at("prompt")) }});
    };

    const auto handle_models = [&params, &ctx_server, &state, &res_ok](const httplib::Request &, httplib::Response & res) {
        server_state current_state = state.load();
        json model_meta = nullptr;
        if (current_state == SERVER_STATE_READY) {
            model_meta = ctx_server.model_meta();
        }
        // Get file metadata
        struct stat file_stat;
        stat(params.model.path.c_str(), &file_stat);

        // Convert modified time to ISO 8601
        char modified_buf[64];
        strftime(modified_buf, sizeof(modified_buf), "%Y-%m-%dT%H:%M:%S%z", localtime(&file_stat.st_mtime));

        const auto* model = llama_get_model(ctx_server.ctx);
        char arch_buf[64] = {0};
        char param_size_buf[64] = {0};
        llama_model_meta_val_str(model, "general.architecture", arch_buf, sizeof(arch_buf));
        llama_model_meta_val_str(model, "general.parameter_count", param_size_buf, sizeof(param_size_buf));

        json models = {
            {"models", {
                {
                    {"name", params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"model", params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"modified_at", modified_buf},
                    {"size", file_stat.st_size},
                    {"digest", ""}, // TODO: add digest
                    {"type", "model"},
                    {"description", ""},
                    {"tags", {arch_buf}},
                    {"capabilities", {"completion"}},
                    {"parameters", ""}, // TODO: add parameters
                    {"details", {
                        {"parent_model", ""}, // TODO: Add parent_model
                        {"format", "gguf"},
                        {"family", arch_buf},
                        {"families", {arch_buf}},
                        {"parameter_size", param_size_buf},
                        {"quantization_level", ""} // TODO: add quantization level if available
                    }}
                }
            }},
            {"object", "list"},

Review comment (suggestion):
I think these are not actually used, they seem to be there so API client doesn't throw an error. I think they can be set to an empty string for now.

Also I think most GGUF out there does not even have this `general.parameter_count` value

Code after:
        json models = {
            {"models", {
                {
                    {"name", params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"model", params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"modified_at", ""},
                    {"size", ""},
                    {"digest", ""}, // dummy value, llama.cpp does not support managing model file's hash
                    {"type", "model"},
                    {"description", ""},
                    {"tags", {""}},
                    {"capabilities", {"completion"}},
                    {"parameters", ""},
                    {"details", {
                        {"parent_model", ""},
                        {"format", "gguf"},
                        {"family", ""},
                        {"families", {""}},
                        {"parameter_size", ""},
                        {"quantization_level", ""}
                    }}
                }
            }},
            {"object", "list"},
            {"data", {
                {
                    {"id",       params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"object",   "model"},
                    {"created",  std::time(0)},
                    {"owned_by", "llamacpp"},
                    {"meta",     model_meta},
                },
            }}
        };

        res_ok(res, models);
    };

    const auto handle_tokenize = [&ctx_server, &res_ok](const httplib::Request & req, httplib::Response & res) {
        const json body = json::parse(req.body);

        json tokens_response = json::array();
        if (body.count("content") != 0) {
            const bool add_special = json_value(body, "add_special", false);
            const bool with_pieces = json_value(body, "with_pieces", false);

            llama_tokens tokens = tokenize_mixed(ctx_server.vocab, body.at("content"), add_special, true);

            if (with_pieces) {
                for (const auto& token : tokens) {
                    std::string piece = common_token_to_piece(ctx_server.ctx, token);