MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / chat_loop

Function chat_loop

smallthinker/tools/run/run.cpp:1179–1205  ·  view source on GitHub ↗

Main chat loop function

Source from the content-addressed store, hash-verified

1177
1178// Main chat loop function
1179static 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
1207static void log_callback(const enum ggml_log_level level, const char * text, void * p) {
1208 const Opt * opt = static_cast<Opt *>(p);

Callers 1

mainFunction · 0.85

Calls 9

read_chat_template_fileFunction · 0.85
is_stdout_a_terminalFunction · 0.85
get_user_inputFunction · 0.85
process_user_messageFunction · 0.85
llama_n_ctxFunction · 0.50
resizeMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected