change:1.配置默认使用v3。2.asio中文转u8。3.com*hpp添加一个trim功能。
This commit is contained in:
parent
40ca781af3
commit
f99b2cbabb
@ -75,6 +75,15 @@ public:
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
buffer_.clear();
|
buffer_.clear();
|
||||||
}
|
}
|
||||||
|
static std::string com_trim(const std::string& input)
|
||||||
|
{
|
||||||
|
size_t start = input.find_first_not_of(" \t\n\r\f\v");
|
||||||
|
if (start == std::string::npos) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
||||||
|
return input.substr(start, end - start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char> buffer_;
|
std::vector<char> buffer_;
|
||||||
@ -120,7 +129,8 @@ inline FrameData* com_parse(CMutBuffer& buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(&protk, buffer.get_data() + find + sizeof(header) + sizeof(type) + sizeof(len) + len, sizeof(protk));
|
std::memcpy(&protk, buffer.get_data() + find + sizeof(header) + sizeof(type) + sizeof(len) + len, sizeof(protk));
|
||||||
std::memcpy(&coptk, buffer.get_data() + find + sizeof(header) + sizeof(type) + sizeof(len) + sizeof(protk) + len, sizeof(coptk));
|
std::memcpy(&coptk, buffer.get_data() + find + sizeof(header) + sizeof(type) + sizeof(len) + sizeof(protk) + len,
|
||||||
|
sizeof(coptk));
|
||||||
|
|
||||||
r = new FrameData();
|
r = new FrameData();
|
||||||
r->type = static_cast<FrameType>(type);
|
r->type = static_cast<FrameType>(type);
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
BaseURL = https://api.lkeap.cloud.tencent.com/v1/chat/completions
|
BaseURL = https://api.lkeap.cloud.tencent.com/v1/chat/completions
|
||||||
ApiEnvKey = TENCENT_DEEPSEEK_KEY
|
ApiEnvKey = TENCENT_DEEPSEEK_KEY
|
||||||
UserName = user
|
UserName = user
|
||||||
ModelName = deepseek-r1
|
ModelName = deepseek-v3
|
||||||
AssistantName = assistant
|
AssistantName = assistant
|
||||||
MaxTokens = 50000
|
MaxTokens = 50000
|
||||||
|
10
server.cxx
10
server.cxx
@ -1,4 +1,5 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
#include "util.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Server::Server(asio::io_context& io_context, short port) : io_context_(io_context), acceptor_(io_context)
|
Server::Server(asio::io_context& io_context, short port) : io_context_(io_context), acceptor_(io_context)
|
||||||
@ -18,12 +19,16 @@ void Server::start()
|
|||||||
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port_);
|
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port_);
|
||||||
try {
|
try {
|
||||||
acceptor_.open(endpoint.protocol());
|
acceptor_.open(endpoint.protocol());
|
||||||
acceptor_.set_option(asio::socket_base::reuse_address(true));
|
// acceptor_.set_option(asio::socket_base::reuse_address(true));
|
||||||
acceptor_.bind(endpoint);
|
acceptor_.bind(endpoint);
|
||||||
acceptor_.listen();
|
acceptor_.listen();
|
||||||
do_accept();
|
do_accept();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::cerr << ansi_to_u8(e.what()) << '\n';
|
||||||
|
#else
|
||||||
std::cerr << e.what() << '\n';
|
std::cerr << e.what() << '\n';
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,8 +128,7 @@ void Server::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket, con
|
|||||||
req.coptk = parse.completion_tokens;
|
req.coptk = parse.completion_tokens;
|
||||||
use_tokens_ += req.protk;
|
use_tokens_ += req.protk;
|
||||||
use_tokens_ += req.coptk;
|
use_tokens_ += req.coptk;
|
||||||
std::cout << "Already use " << use_tokens_ << " tokens.\r";
|
std::cout << "Already use " << use_tokens_ << " tokens.\n";
|
||||||
std::cout.flush();
|
|
||||||
memcpy(req.data, parse.message_content.c_str(), parse.message_content.size());
|
memcpy(req.data, parse.message_content.c_str(), parse.message_content.size());
|
||||||
req.data[req.len - 1] = '\0';
|
req.data[req.len - 1] = '\0';
|
||||||
send_frame(socket, req);
|
send_frame(socket, req);
|
||||||
|
31
util.hpp
Normal file
31
util.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef UTIL_HPP
|
||||||
|
#define UTIL_HPP
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string ansi_to_u8(const std::string& str)
|
||||||
|
{
|
||||||
|
int wideCharLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
|
||||||
|
if (wideCharLen <= 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::wstring wideStr(wideCharLen, L'\0');
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &wideStr[0], wideCharLen);
|
||||||
|
|
||||||
|
int utf8Len = WideCharToMultiByte(CP_UTF8, 0, wideStr.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||||
|
if (utf8Len <= 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string utf8Str(utf8Len, '\0');
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wideStr.c_str(), -1, &utf8Str[0], utf8Len, nullptr, nullptr);
|
||||||
|
|
||||||
|
utf8Str.resize(utf8Len - 1);
|
||||||
|
return utf8Str;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // UTIL_HPP
|
Loading…
x
Reference in New Issue
Block a user