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

Function main

subprojects/llama.cpp/tools/cli/cli.cpp:189–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187};
188
189int main(int argc, char ** argv) {
190 common_params params;
191
192 params.verbosity = LOG_LEVEL_ERROR; // by default, less verbose logs
193
194 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_CLI)) {
195 return 1;
196 }
197
198 // TODO: maybe support it later?
199 if (params.conversation_mode == COMMON_CONVERSATION_MODE_DISABLED) {
200 console::error("--no-conversation is not supported by llama-cli\n");
201 console::error("please use llama-completion instead\n");
202 }
203
204 common_init();
205
206 // struct that contains llama context and inference
207 cli_context ctx_cli(params);
208
209 llama_backend_init();
210 llama_numa_init(params.numa);
211
212 // TODO: avoid using atexit() here by making `console` a singleton
213 console::init(params.simple_io, params.use_color);
214 atexit([]() { console::cleanup(); });
215
216 console::set_display(DISPLAY_TYPE_RESET);
217
218#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
219 struct sigaction sigint_action;
220 sigint_action.sa_handler = signal_handler;
221 sigemptyset (&sigint_action.sa_mask);
222 sigint_action.sa_flags = 0;
223 sigaction(SIGINT, &sigint_action, NULL);
224 sigaction(SIGTERM, &sigint_action, NULL);
225#elif defined (_WIN32)
226 auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
227 return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
228 };
229 SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
230#endif
231
232 console::log("\nLoading model... "); // followed by loading animation
233 console::spinner::start();
234 if (!ctx_cli.ctx_server.load_model(params)) {
235 console::spinner::stop();
236 console::error("\nFailed to load the model\n");
237 return 1;
238 }
239
240 console::spinner::stop();
241 console::log("\n");
242
243 std::thread inference_thread([&ctx_cli]() {
244 ctx_cli.ctx_server.start_loop();
245 });
246

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
errorFunction · 0.85
common_initFunction · 0.85
llama_backend_initFunction · 0.85
llama_numa_initFunction · 0.85
cleanupFunction · 0.85
set_displayFunction · 0.85
logFunction · 0.85
startFunction · 0.85
readlineFunction · 0.85
should_stopFunction · 0.85
string_stripFunction · 0.85

Tested by

no test coverage detected