MCPcopy Create free account
hub / github.com/alibaba/MNN / main

Function main

apps/mnncli/examples/model_runner_example.cpp:15–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using namespace MNN::Transformer;
14
15int main(int argc, const char* argv[]) {
16 if (argc < 2) {
17 std::cout << "Usage: " << argv[0] << " config.json [prompt.txt] or -p \"prompt\"" << std::endl;
18 std::cout << "Examples:" << std::endl;
19 std::cout << " " << argv[0] << " config.json # Interactive chat mode" << std::endl;
20 std::cout << " " << argv[0] << " config.json prompts.txt # Evaluate prompts from file" << std::endl;
21 std::cout << " " << argv[0] << " config.json -p \"Hello, world!\" # Process single prompt" << std::endl;
22#ifdef LLM_SUPPORT_VISION
23 std::cout << " " << argv[0] << " config.json -p \"Describe this video:<video>/path/to/video.mp4</video>\" # Process video" << std::endl;
24#endif
25 return 0;
26 }
27
28 try {
29 // Initialize LLM
30 std::string config_path = argv[1];
31 std::cout << "Loading LLM from config: " << config_path << std::endl;
32
33 std::unique_ptr<Llm> llm(Llm::createLLM(config_path));
34 llm->set_config("{\"tmp_path\":\"tmp\"}");
35 llm->load();
36
37 // Create ModelRunner
38 ModelRunner runner(llm.get());
39
40 // Handle different command line arguments
41 if (argc > 2) {
42 std::string prompt_arg = argv[2];
43
44 if (prompt_arg == "-p") {
45 if (argc > 3) {
46 std::string prompt_str = argv[3];
47 std::cout << "Processing prompt: " << prompt_str << std::endl;
48 runner.ProcessPrompt(prompt_str);
49 } else {
50 std::cerr << "Error: -p flag requires a prompt string." << std::endl;
51 return 1;
52 }
53 } else {
54 // Treat as prompt file
55 std::cout << "Evaluating prompts from file: " << prompt_arg << std::endl;
56 runner.EvalFile(prompt_arg);
57 }
58 } else {
59 // Interactive chat mode
60 std::cout << "Starting interactive chat mode..." << std::endl;
61 runner.InteractiveChat();
62 }
63
64 } catch (const std::exception& e) {
65 std::cerr << "Error: " << e.what() << std::endl;
66 return 1;
67 }
68
69 return 0;
70}

Callers

nothing calls this directly

Calls 7

ProcessPromptMethod · 0.80
EvalFileMethod · 0.80
InteractiveChatMethod · 0.80
set_configMethod · 0.45
loadMethod · 0.45
getMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected