MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / read_file

Function read_file

subprojects/llama.cpp/tests/test-chat.cpp:94–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94static 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
112static 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)));

Callers 1

read_templatesFunction · 0.70

Calls 3

resizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected