openai-api/server/config.cxx

51 lines
1.7 KiB
C++
Raw Normal View History

2025-04-14 21:01:36 +08:00
#include "config.h"
2025-03-04 15:17:10 +08:00
#include <SimpleIni.h>
#include <iostream>
2025-04-14 21:01:36 +08:00
bool ConfigSet::parse_config(Configuration& config, const std::string& config_path)
2025-03-04 15:17:10 +08:00
{
CSimpleIniA ini_handle{};
SI_Error ret = ini_handle.LoadFile(config_path.c_str());
if (ret != SI_OK) {
return false;
}
if (!ini_handle.KeyExists("Config", "BaseURL")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/BaseURL in openai.ini" << std::endl;
2025-03-04 15:17:10 +08:00
return false;
}
config.base_url = ini_handle.GetValue("Config", "BaseURL");
if (!ini_handle.KeyExists("Config", "ApiEnvKey")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/ApiEnvKey in openai.ini" << std::endl;
2025-03-04 15:17:10 +08:00
return false;
}
config.api_env_key = ini_handle.GetValue("Config", "ApiEnvKey");
if (!ini_handle.KeyExists("Config", "UserName")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/UserName in openai.ini" << std::endl;
2025-03-04 15:17:10 +08:00
return false;
}
config.user_name = ini_handle.GetValue("Config", "UserName");
if (!ini_handle.KeyExists("Config", "ModelName")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/ModelName in openai.ini" << std::endl;
2025-03-04 15:17:10 +08:00
return false;
}
config.model_name = ini_handle.GetValue("Config", "ModelName");
if (!ini_handle.KeyExists("Config", "AssistantName")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/AssistantName in openai.ini" << std::endl;
2025-03-04 15:17:10 +08:00
return false;
}
config.assistant_name = ini_handle.GetValue("Config", "AssistantName");
2025-03-05 09:20:03 +08:00
if (!ini_handle.KeyExists("Config", "MaxTokens")) {
2025-03-05 09:25:19 +08:00
std::cerr << "Not Key Found Config/MaxTokens in openai.ini" << std::endl;
2025-03-05 09:20:03 +08:00
return false;
}
config.max_tokens = ini_handle.GetLongValue("Config", "MaxTokens");
2025-03-04 15:17:10 +08:00
return true;
}