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

Method Handle

apps/mnncli/src/handlers/serve_command_handler.cpp:53–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53int ServeCommandHandler::Handle(const ParsedCommand& cmd) {
54 std::string model_name;
55 std::string config_path;
56 std::string host;
57 int port = -1;
58 bool has_thinking_override = false;
59 bool thinking_enabled = true;
60
61 // Extract options
62 host = CommandParser::GetOption(cmd, "host", "");
63 auto port_str = CommandParser::GetOption(cmd, "port", "");
64 config_path = CommandParser::GetOption(cmd, "config", "");
65 auto thinking_value = CommandParser::GetOption(cmd, "thinking", "");
66 has_thinking_override = !thinking_value.empty();
67 if (has_thinking_override && !TryParseThinkingOption(thinking_value, thinking_enabled)) {
68 UserInterface::ShowError("Invalid thinking option value",
69 "Use --thinking true|false (also supports 1|0, on|off, yes|no)");
70 std::cout << MakeUsage(mnncli::GetSpec("serve")) << "\n";
71 return 1;
72 }
73
74 // Determine model name (if provided as positional)
75 if (!cmd.arguments.empty()) {
76 model_name = cmd.arguments[0];
77 }
78
79 // Load config for defaults
80 auto& config_mgr = ConfigManager::GetInstance();
81 auto app_config = config_mgr.LoadConfig();
82
83 if (host.empty()) {
84 host = app_config.api_host.empty() ? std::string("127.0.0.1") : app_config.api_host;
85 }
86 if (!port_str.empty()) {
87 try { port = std::stoi(port_str); } catch (...) { port = -1; }
88 }
89 if (port <= 0) {
90 port = app_config.api_port > 0 ? app_config.api_port : 8000;
91 }
92
93 // Resolve config path
94 if (config_path.empty()) {
95 if (model_name.empty()) {
96 if (!app_config.default_model.empty()) {
97 model_name = app_config.default_model;
98 LOG_INFO("Using default model: " + model_name);
99 } else {
100 UserInterface::ShowError("Model name required and no default model set",
101 "Set a default model with: mnncli config set default_model <model_name>");
102 std::cout << MakeUsage(mnncli::GetSpec("serve")) << "\n";
103 return 1;
104 }
105 }
106 config_path = FileUtils::GetConfigPath(model_name);
107 } else {
108 // Expand ~ in config path and best-effort derive model name
109 config_path = FileUtils::ExpandTilde(config_path);
110 std::string config_dir = fs::path(config_path).parent_path().string();

Callers

nothing calls this directly

Calls 15

MakeUsageFunction · 0.85
transformFunction · 0.85
LoadConfigMethod · 0.80
TryParseThinkingOptionFunction · 0.70
stringFunction · 0.50
pathFunction · 0.50
to_stringFunction · 0.50
emptyMethod · 0.45
stringMethod · 0.45
filenameMethod · 0.45
set_configMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected