diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index a552f646f1..2923534fb7 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include "AtomMap.h" #include "device.h" @@ -1112,12 +1115,16 @@ template void deepmd::select_map_inv( #endif void deepmd::read_file_to_string(std::string model, std::string& file_content) { -#ifdef BUILD_TENSORFLOW - deepmd::check_status(tensorflow::ReadFileToString(tensorflow::Env::Default(), - model, &file_content)); -#else - throw deepmd::deepmd_exception("TODO: read_file_to_string only support TF"); -#endif + // generated by GitHub Copilot + std::ifstream file(model); + if (file.is_open()) { + std::stringstream buffer; + buffer << file.rdbuf(); + file_content = buffer.str(); + file.close(); + } else { + throw deepmd::deepmd_exception("Failed to open file: " + model); + } } void deepmd::convert_pbtxt_to_pb(std::string fn_pb_txt, std::string fn_pb) {