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

Method ListLocalModelsInner

apps/mnncli/src/local_model_utils.cpp:55–124  ·  view source on GitHub ↗

Get local models from a specific provider's directory Only checks the provider directory for two-level directory structure: / / / Example: /home/cache/ModelScope/Qwen/Qwen3_VXX-ssf -> "Qwen/Qwen3_VXX-ssf" Only returns models that have .mnncli/.complete marker (fully downloaded) Args: provider: Provider name (e.g., "HuggingFace", "ModelScope", "Modelers") cac

Source from the content-addressed store, hash-verified

53// Returns:
54// Vector of model names in "owner/model_name" format
55std::vector<std::string> LocalModelUtils::ListLocalModelsInner(const std::string& provider,
56 const std::string& cache_dir) {
57 std::vector<std::string> model_names;
58
59 // Get cache directory - use provided one for testing, or ConfigManager for production
60 std::string expanded_cache_dir;
61 std::string local_cache_dir = cache_dir;
62
63 if (local_cache_dir.length() > 0) {
64 if (local_cache_dir.back() == '/' || local_cache_dir.back() == '\\') {
65 local_cache_dir.pop_back();
66 }
67 expanded_cache_dir = local_cache_dir;
68 } else {
69 auto& config_mgr = ConfigManager::GetInstance();
70 expanded_cache_dir = config_mgr.GetBaseCacheDir();
71 }
72
73 // Build provider directory path
74 std::string provider_dir = expanded_cache_dir + "/" + provider;
75
76 // Debug output
77 LOG_DEBUG_TAG("Scanning provider directory: " + provider_dir, "LocalModelUtils");
78
79 // Check if provider directory exists
80 std::error_code ec;
81 if (!fs::exists(provider_dir, ec) || !fs::is_directory(provider_dir, ec)) {
82 LOG_DEBUG_TAG("Provider directory does not exist: " + provider_dir, "LocalModelUtils");
83 return model_names; // Return empty vector
84 }
85
86 // Scan for two-level directory structure: provider/owner/model_name
87 for (const auto &owner_entry : fs::directory_iterator(provider_dir, ec)) {
88 if (ec) {
89 continue;
90 }
91
92 // Check if it's a directory (owner level)
93 if (!fs::is_directory(owner_entry, ec)) {
94 continue;
95 }
96
97 std::string owner_name = owner_entry.path().filename().string();
98 // Skip hidden directories
99 if (owner_name.empty() || owner_name[0] == '.') {
100 continue;
101 }
102
103 // Scan model directories under owner
104 std::string owner_path = owner_entry.path().string();
105 for (const auto &model_entry : fs::directory_iterator(owner_path, ec)) {
106 if (ec) {
107 continue;
108 }
109
110 // Check if it's a directory (model level)
111 if (fs::is_directory(model_entry, ec)) {
112 std::string model_path = model_entry.path().string();

Callers

nothing calls this directly

Calls 13

existsFunction · 0.85
backMethod · 0.80
sortFunction · 0.50
to_stringFunction · 0.50
lengthMethod · 0.45
GetBaseCacheDirMethod · 0.45
stringMethod · 0.45
filenameMethod · 0.45
pathMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected