一个可用版本(通信正常,但是server未成功)。

This commit is contained in:
taynpg 2025-03-04 20:24:20 +08:00
parent 8f95f666e2
commit 6e7c4a0a03
4 changed files with 35 additions and 15 deletions

View File

@ -18,7 +18,7 @@
}
],
"args": [
"/home/yun/Code/filecomplete", "cpp,h", "/home/yun/Code/question.txt"
"9999"
]
},
"cmake.configureSettings": {

View File

@ -1,6 +1,6 @@
[Config]
BaseURL =
ApiEnvKey =
UserName =
ModelName =
AssistantName =
BaseURL = https://api.lkeap.cloud.tencent.com/v1/chat/completions
ApiEnvKey = TENCENT_DEEPSEEK_KEY
UserName = user
ModelName = deepseek-r1
AssistantName = assistant

View File

@ -35,6 +35,10 @@ int main(int argc, char* argv[])
return 0;
}
#ifdef _WIN32
system("chcp 65001");
#endif
int port = std::stoi(argv[1]);
ConfigInfo config;
@ -50,10 +54,10 @@ int main(int argc, char* argv[])
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;
}
// 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);
@ -61,8 +65,27 @@ int main(int argc, char* argv[])
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);
// 测试是否正常
// auto req_str = json->format_request("你好啊,介绍一下自己。");
// std::string out;
// if (!api->post(req_str, out)) {
// std::cout << "post error!" << std::endl;
// return -2;
// }
// std::cout << "post success!" << std::endl;
// auto re = json->parse(out);
// std::string use = "本次tokens消耗:" + std::to_string(re.prompt_tokens) + "+" + std::to_string(re.completion_tokens) + "=" +
// std::to_string(re.total_tokens);
// std::cout << use << std::endl;
// std::cout << re.reasoning_content << std::endl;
// std::cout << re.message_content << std::endl;
// std::cout << "success." << std::endl;
server.set_worker(api, json);
server.start();
return 0;
}

View File

@ -8,11 +8,8 @@ Server::Server(asio::io_context& io_context, short port)
void Server::start()
{
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), 8080);
try {
acceptor_.open(endpoint.protocol());
acceptor_.set_option(asio::socket_base::reuse_address(true));
acceptor_.bind(endpoint);
acceptor_.listen();
do_accept();
} catch (const std::exception& e) {
@ -98,7 +95,7 @@ void Server::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket, con
std::string Server::post_data(const std::string& data)
{
return std::string();
return json_->format_request(data);
}
bool Server::send_frame(const std::shared_ptr<asio::ip::tcp::socket>& socket, FrameData& data)