openai-api/server/config.cxx

51 lines
1.7 KiB
C++

#include "config.h"
#include <SimpleIni.h>
#include <iostream>
bool ConfigSet::parse_config(Configuration& config, const std::string& config_path)
{
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")) {
std::cerr << "Not Key Found Config/BaseURL in openai.ini" << std::endl;
return false;
}
config.base_url = ini_handle.GetValue("Config", "BaseURL");
if (!ini_handle.KeyExists("Config", "ApiEnvKey")) {
std::cerr << "Not Key Found Config/ApiEnvKey in openai.ini" << std::endl;
return false;
}
config.api_env_key = ini_handle.GetValue("Config", "ApiEnvKey");
if (!ini_handle.KeyExists("Config", "UserName")) {
std::cerr << "Not Key Found Config/UserName in openai.ini" << std::endl;
return false;
}
config.user_name = ini_handle.GetValue("Config", "UserName");
if (!ini_handle.KeyExists("Config", "ModelName")) {
std::cerr << "Not Key Found Config/ModelName in openai.ini" << std::endl;
return false;
}
config.model_name = ini_handle.GetValue("Config", "ModelName");
if (!ini_handle.KeyExists("Config", "AssistantName")) {
std::cerr << "Not Key Found Config/AssistantName in openai.ini" << std::endl;
return false;
}
config.assistant_name = ini_handle.GetValue("Config", "AssistantName");
if (!ini_handle.KeyExists("Config", "MaxTokens")) {
std::cerr << "Not Key Found Config/MaxTokens in openai.ini" << std::endl;
return false;
}
config.max_tokens = ini_handle.GetLongValue("Config", "MaxTokens");
return true;
}