| 39 | } |
| 40 | |
| 41 | bool 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 | |
| 73 | void ConfigManager::ShowConfig(const Config& config) { |
| 74 | std::cout << "Configuration:\n"; |