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