| 92 | } |
| 93 | |
| 94 | static std::string read_file(const std::string & path) { |
| 95 | std::cerr << "# Reading: " << path << '\n' << std::flush; |
| 96 | std::ifstream fs(path, std::ios_base::binary); |
| 97 | if (!fs.is_open()) { |
| 98 | fs = std::ifstream("../" + path, std::ios_base::binary); |
| 99 | if (!fs.is_open()) { |
| 100 | throw std::runtime_error("Failed to open file: " + path); |
| 101 | } |
| 102 | } |
| 103 | fs.seekg(0, std::ios_base::end); |
| 104 | auto size = fs.tellg(); |
| 105 | fs.seekg(0); |
| 106 | std::string out; |
| 107 | out.resize(static_cast<size_t>(size)); |
| 108 | fs.read(out.data(), static_cast<std::streamsize>(size)); |
| 109 | return out; |
| 110 | } |
| 111 | |
| 112 | static common_chat_templates_ptr read_templates(const std::string & path) { |
| 113 | return common_chat_templates_ptr(common_chat_templates_init(/* model= */ nullptr, read_file(path))); |
no test coverage detected