69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
|
|
#include "handle.h"
|
|
#include "jsondata.h"
|
|
#include "server.h"
|
|
#include "zapi.h"
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
std::string get_key(const std::string& env_key)
|
|
{
|
|
char* v = getenv(env_key.c_str());
|
|
if (v) {
|
|
return std::string(v);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
std::string show_api(const std::string& api)
|
|
{
|
|
if (api.empty()) {
|
|
return "NULL";
|
|
}
|
|
if (api.size() > 10) {
|
|
return api.substr(0, 10) + "...";
|
|
} else {
|
|
return "NULL";
|
|
}
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (argc < 2) {
|
|
std::cout << "note: you can give port to start." << std::endl;
|
|
return 0;
|
|
}
|
|
|
|
int port = std::stoi(argv[1]);
|
|
|
|
ConfigInfo config;
|
|
if (!CConfig::parse_config(config, "deepseek.ini")) {
|
|
std::cerr << "parse config failed." << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
auto key = get_key(config.api_env_key);
|
|
std::cout << "api_key:" << config.api_env_key << std::endl;
|
|
std::cout << "assis_name:" << config.assistant_name << std::endl;
|
|
std::cout << "base_url:" << config.base_url << std::endl;
|
|
std::cout << "model_name:" << config.model_name << std::endl;
|
|
std::cout << "api:" << show_api(key) << std::endl;
|
|
|
|
if (show_api(key) == "NULL") {
|
|
std::cerr << "api is invalid." << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
auto api = std::make_shared<COpenAI>();
|
|
api->set_base(config.base_url, key);
|
|
|
|
auto json = std::make_shared<CJsonOper>(config.user_name, config.model_name, config.assistant_name);
|
|
asio::io_context io_context;
|
|
Server server(io_context, port);
|
|
server.set_worker(api, json);
|
|
server.start();
|
|
|
|
return 0;
|
|
}
|