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

Method Handle

apps/mnncli/src/handlers/run_command_handler.cpp:54–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54int RunCommandHandler::Handle(const ParsedCommand& cmd) {
55 std::string model_name;
56 std::string config_path;
57 std::string prompt;
58 std::string prompt_file;
59 std::string thinking_value;
60 bool has_thinking_override = false;
61 bool thinking_enabled = true;
62
63 // Extract options from parsed command
64 prompt = CommandParser::GetOption(cmd, "prompt", "");
65 prompt_file = CommandParser::GetOption(cmd, "file", "");
66 config_path = CommandParser::GetOption(cmd, "config", "");
67 thinking_value = CommandParser::GetOption(cmd, "thinking", "");
68 has_thinking_override = !thinking_value.empty();
69 if (has_thinking_override && !TryParseThinkingOption(thinking_value, thinking_enabled)) {
70 UserInterface::ShowError("Invalid thinking option value",
71 "Use --thinking true|false (also supports 1|0, on|off, yes|no)");
72 PrintRunUsage();
73 return 1;
74 }
75
76 // Determine model name
77 if (!cmd.arguments.empty()) {
78 model_name = cmd.arguments[0];
79 }
80
81 LOG_INFO("Parsed arguments. model_name='" + model_name + "', config_path='" + config_path + "', prompt='" + prompt + "', prompt_file='" + prompt_file + "'");
82 // If no config path specified, check if we have a model name or can use default model
83 if (config_path.empty()) {
84 if (model_name.empty()) {
85 // No model name provided, try to use default model
86 auto& config_mgr = ConfigManager::GetInstance();
87 auto config = config_mgr.LoadConfig();
88 if (!config.default_model.empty()) {
89 model_name = config.default_model;
90 LOG_INFO("Using default model: " + model_name);
91 } else {
92 UserInterface::ShowError("Model name required and no default model set",
93 "Set a default model with: mnncli config set default_model <model_name>");
94 PrintRunUsage();
95 return 1;
96 }
97 }
98 config_path = FileUtils::GetConfigPath(model_name);
99 } else {
100 // If config path is specified, extract model name from path or use a default
101 std::string config_dir = fs::path(config_path).parent_path().string();
102 std::string config_filename = fs::path(config_dir).filename().string();
103 if (!config_filename.empty()) {
104 model_name = config_filename;
105 } else {
106 model_name = "custom_model";
107 }
108 // Expand ~ in config path
109 config_path = FileUtils::ExpandTilde(config_path);
110 }
111

Callers 1

DispatchMethod · 0.45

Calls 12

LoadConfigMethod · 0.80
InteractiveChatMethod · 0.80
EvalPromptsMethod · 0.80
EvalFileMethod · 0.80
TryParseThinkingOptionFunction · 0.70
pathFunction · 0.50
stringFunction · 0.50
emptyMethod · 0.45
stringMethod · 0.45
filenameMethod · 0.45
set_configMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected