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

Method SaveConfig

apps/mnncli/src/cli_config_manager.cpp:41–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41bool ConfigManager::SaveConfig(const Config& config) {
42 try {
43 std::string config_path = GetConfigFilePath();
44 std::string config_dir = fs::path(config_path).parent_path().string();
45
46 if (!fs::exists(config_dir)) {
47 fs::create_directories(config_dir);
48 }
49
50 nlohmann::json j;
51 j["default_model"] = config.default_model;
52 j["cache_dir"] = config.cache_dir;
53 j["log_level"] = config.log_level;
54 j["default_max_tokens"] = config.default_max_tokens;
55 j["default_temperature"] = config.default_temperature;
56 j["api_host"] = config.api_host;
57 j["api_port"] = config.api_port;
58 j["download_provider"] = config.download_provider;
59
60 std::ofstream file(config_path);
61 if (file.is_open()) {
62 file << j.dump(2);
63 file.close();
64 current_config_ = config;
65 return true;
66 }
67 } catch (...) {
68 std::cerr << "Failed to save configuration file." << std::endl;
69 }
70 return false;
71}
72
73void ConfigManager::ShowConfig(const Config& config) {
74 std::cout << "Configuration:\n";

Callers 1

HandleMethod · 0.80

Calls 7

existsFunction · 0.85
create_directoriesFunction · 0.85
pathFunction · 0.50
stringMethod · 0.45
is_openMethod · 0.45
dumpMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected