Main chat loop function
| 1177 | |
| 1178 | // Main chat loop function |
| 1179 | static int chat_loop(LlamaData & llama_data, const Opt & opt) { |
| 1180 | int prev_len = 0; |
| 1181 | llama_data.fmtted.resize(llama_n_ctx(llama_data.context.get())); |
| 1182 | std::string chat_template; |
| 1183 | if (!opt.chat_template_file.empty()) { |
| 1184 | chat_template = read_chat_template_file(opt.chat_template_file); |
| 1185 | } |
| 1186 | |
| 1187 | common_chat_templates_ptr chat_templates = common_chat_templates_init(llama_data.model.get(), chat_template); |
| 1188 | static const bool stdout_a_terminal = is_stdout_a_terminal(); |
| 1189 | while (true) { |
| 1190 | // Get user input |
| 1191 | std::string user_input; |
| 1192 | if (get_user_input(user_input, opt.user) == 1) { |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
| 1196 | const int ret = process_user_message(opt, user_input, llama_data, chat_templates, prev_len, stdout_a_terminal); |
| 1197 | if (ret == 1) { |
| 1198 | return 1; |
| 1199 | } else if (ret == 2) { |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | static void log_callback(const enum ggml_log_level level, const char * text, void * p) { |
| 1208 | const Opt * opt = static_cast<Opt *>(p); |
no test coverage detected