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

Code before:
        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"},
            {"data", {
                {
                    {"id",       params.model_alias.empty() ? params.model.path : params.model_alias},
                    {"object",   "model"},
                    {"created",  std::time(0)},
                    {"owned_by", "llamacpp"},
                    {"meta",     model_meta},
                },
            }}

Review comment (suggestion):
```suggestion
                    {"digest", ""}, // dummy value, llama.cpp does not support managing model file's hash
```

This is not a TODO because we don't plan to have this feature

Code after:
                    {"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);
                    json piece_json;

                    // Check if the piece is valid UTF-8
                    if (is_valid_utf8(piece)) {
                        piece_json = piece;
                    } else {
                        // If not valid UTF-8, store as array of byte values
                        piece_json = json::array();
                        for (unsigned char c : piece) {