clang-tidy修改。
This commit is contained in:
parent
a7c61f6ea2
commit
4869b0d494
18
.clang-tidy
18
.clang-tidy
@ -1,4 +1,5 @@
|
||||
Checks: '-*,
|
||||
Checks: "-*,
|
||||
|
||||
clang-*,
|
||||
|
||||
google-build-explicit-make-pair,
|
||||
@ -9,11 +10,12 @@ Checks: '-*,
|
||||
google-runtime-int,
|
||||
google-runtime-operator,
|
||||
|
||||
readability-non-const-parameter,
|
||||
|
||||
-readability-non-const-parameter,
|
||||
readability-avoid-const-params-in-decls,
|
||||
readability-const-return-type,
|
||||
readability-container-size-empty,
|
||||
readability-convert-member-functions-to-static,
|
||||
-readability-convert-member-functions-to-static,
|
||||
readability-delete-null-pointer,
|
||||
readability-deleted-default,
|
||||
readability-make-member-function-const,
|
||||
@ -33,7 +35,8 @@ Checks: '-*,
|
||||
|
||||
cert-dcl21-cpp,
|
||||
cert-dcl50-cpp,
|
||||
cert-env33-c,
|
||||
# 不要使用 system()
|
||||
-cert-env33-c,
|
||||
cert-err34-c,
|
||||
cert-err52-cpp,
|
||||
cert-flp30-c,
|
||||
@ -46,7 +49,7 @@ Checks: '-*,
|
||||
modernize-loop-convert,
|
||||
modernize-make-shared,
|
||||
modernize-make-unique,
|
||||
modernize-pass-by-value,
|
||||
-modernize-pass-by-value,
|
||||
modernize-raw-string-literal,
|
||||
modernize-redundant-void-arg,
|
||||
modernize-replace-auto-ptr,
|
||||
@ -130,7 +133,6 @@ Checks: '-*,
|
||||
performance-unnecessary-copy-initialization,
|
||||
|
||||
boost-use-to-string,
|
||||
boost-use-ranges,
|
||||
'
|
||||
boost-use-ranges"
|
||||
|
||||
WarningsAsErrors: '*'
|
||||
WarningsAsErrors: "*"
|
||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,8 +1,6 @@
|
||||
{
|
||||
"files.autoSave": "onFocusChange",
|
||||
"editor.fontSize": 14,
|
||||
"editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'",
|
||||
"terminal.integrated.fontFamily": "Monaspace Krypton Light",
|
||||
"cmake.configureOnOpen": true,
|
||||
"cmake.debugConfig": {
|
||||
"console": "integratedTerminal",
|
||||
@ -39,6 +37,7 @@
|
||||
"--all-scopes-completion",
|
||||
"--completion-style=detailed",
|
||||
"-j=4",
|
||||
"--clang-tidy",
|
||||
"--pch-storage=memory",
|
||||
"--compile-commands-dir=build",
|
||||
"--background-index",
|
||||
|
@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(/utf-8)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
add_definitions(-D_WIN32_WINNT=0x0601)
|
||||
|
@ -64,5 +64,4 @@ FrameData* OpenAIClient::ask_openai(const std::string& text)
|
||||
|
||||
void OpenAIClient::disconnect()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
class OpenAIClient
|
||||
{
|
||||
public:
|
||||
OpenAIClient(asio::io_context& io_context);
|
||||
explicit OpenAIClient(asio::io_context& io_context);
|
||||
|
||||
public:
|
||||
bool connect(const std::string& ip, unsigned int port);
|
||||
@ -15,11 +15,11 @@ public:
|
||||
void disconnect();
|
||||
|
||||
private:
|
||||
std::string ip_{};
|
||||
std::string port_{};
|
||||
std::string ip_;
|
||||
std::string port_;
|
||||
asio::ip::tcp::socket socket_;
|
||||
asio::io_context& io_context_;
|
||||
CMutBuffer buffer_{};
|
||||
CMutBuffer buffer_;
|
||||
std::array<char, g_BuffSize> tmp_buf_{};
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@ struct Configuration {
|
||||
std::string user_name;
|
||||
std::string model_name;
|
||||
std::string assistant_name;
|
||||
long max_tokens{};
|
||||
int32_t max_tokens{};
|
||||
};
|
||||
|
||||
class ConfigSet
|
||||
@ -16,6 +16,7 @@ class ConfigSet
|
||||
public:
|
||||
ConfigSet() = default;
|
||||
~ConfigSet() = default;
|
||||
|
||||
public:
|
||||
static bool parse_config(Configuration& config, const std::string& config_path = "");
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "jsondata.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
CJsonOper::CJsonOper(const std::string& user_name, const std::string& model, const std::string& assistant_name)
|
||||
: user_(user_name), model_(model), assistant_(assistant_name)
|
||||
@ -92,15 +92,15 @@ size_t CJsonOper::get_u8_len(unsigned char ch)
|
||||
{
|
||||
if (ch <= 0x7F) {
|
||||
return 1;
|
||||
} else if ((ch & 0xE0) == 0xC0) {
|
||||
} else if ((ch & (unsigned char)0xE0) == 0xC0) {
|
||||
return 2;
|
||||
} else if ((ch & 0xF0) == 0xE0) {
|
||||
} else if ((ch & (unsigned char)0xF0) == 0xE0) {
|
||||
return 3;
|
||||
} else if ((ch & 0xF8) == 0xF0) {
|
||||
} else if ((ch & (unsigned char)0xF8) == 0xF0) {
|
||||
return 4;
|
||||
} else if ((ch & 0xFC) == 0xF8) {
|
||||
} else if ((ch & (unsigned char)0xFC) == 0xF8) {
|
||||
return 5;
|
||||
} else if ((ch & 0xFE) == 0xFC) {
|
||||
} else if ((ch & (unsigned char)0xFE) == 0xFC) {
|
||||
return 6;
|
||||
} else {
|
||||
std::cerr << "invalid u8 first ch." << std::endl;
|
||||
@ -118,4 +118,3 @@ std::string CJsonOper::trim(const std::string& input)
|
||||
size_t end = input.find_last_not_of(" \t\n\r\f\v");
|
||||
return input.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
// 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::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;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "server.h"
|
||||
|
||||
#include <cstdint>
|
||||
#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, uint16_t port) : io_context_(io_context), acceptor_(io_context)
|
||||
{
|
||||
port_ = port;
|
||||
}
|
||||
@ -44,7 +44,7 @@ void Server::set_worker(std::shared_ptr<COpenAI> worker, std::shared_ptr<CJsonOp
|
||||
json_ = json;
|
||||
}
|
||||
|
||||
void Server::set_token(long tokens)
|
||||
void Server::set_token(int32_t tokens)
|
||||
{
|
||||
tokens_ = tokens;
|
||||
}
|
||||
@ -58,9 +58,8 @@ void Server::do_accept()
|
||||
std::string client_key = endpoint.address().to_string() + ":" + std::to_string(endpoint.port());
|
||||
std::unique_lock<std::mutex> lock(cli_mutex_);
|
||||
client_map_[client_key] = std::make_shared<ClientCache>();
|
||||
clients_.insert(
|
||||
std::make_pair(socket->remote_endpoint().address().to_string(),
|
||||
std::thread([this, socket, client_key]() { th_client(socket, client_key); })));
|
||||
clients_.insert(std::make_pair(socket->remote_endpoint().address().to_string(),
|
||||
std::thread([this, socket, client_key]() { th_client(socket, client_key); })));
|
||||
}
|
||||
|
||||
do_accept();
|
||||
@ -100,7 +99,7 @@ void Server::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket, con
|
||||
cache->buffer_.push(cache->tmp_buf_.data(), len);
|
||||
|
||||
while (true) {
|
||||
auto frame = com_parse(cache->buffer_);
|
||||
auto* frame = com_parse(cache->buffer_);
|
||||
if (frame == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
@ -11,13 +11,13 @@
|
||||
|
||||
struct ClientCache {
|
||||
std::array<char, g_BuffSize> tmp_buf_{};
|
||||
CMutBuffer buffer_{};
|
||||
CMutBuffer buffer_;
|
||||
};
|
||||
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
Server(asio::io_context& io_context, short port);
|
||||
Server(asio::io_context& io_context, uint16_t port);
|
||||
~Server();
|
||||
|
||||
public:
|
||||
@ -26,7 +26,7 @@ public:
|
||||
|
||||
public:
|
||||
void set_worker(std::shared_ptr<COpenAI> worker, std::shared_ptr<CJsonOper> json);
|
||||
void set_token(long tokens);
|
||||
void set_token(int32_t tokens);
|
||||
|
||||
private:
|
||||
void do_accept();
|
||||
@ -40,16 +40,16 @@ private:
|
||||
asio::io_context& io_context_;
|
||||
asio::ip::tcp::acceptor acceptor_;
|
||||
|
||||
std::shared_ptr<COpenAI> worker_{};
|
||||
std::shared_ptr<CJsonOper> json_{};
|
||||
std::shared_ptr<COpenAI> worker_;
|
||||
std::shared_ptr<CJsonOper> json_;
|
||||
std::mutex ask_mutex_;
|
||||
std::mutex cli_mutex_;
|
||||
std::unordered_map<std::string, std::thread> clients_;
|
||||
std::map<std::string, std::shared_ptr<ClientCache>> client_map_;
|
||||
CMutBuffer buffer_{};
|
||||
short port_;
|
||||
long tokens_{};
|
||||
long use_tokens_{};
|
||||
CMutBuffer buffer_;
|
||||
uint16_t port_;
|
||||
int32_t tokens_{};
|
||||
int32_t use_tokens_{};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@ bool COpenAI::post(const std::string& json, std::string& out)
|
||||
if (res != CURLE_OK) {
|
||||
std::cerr << "curl post failed: " << curl_easy_strerror(res) << std::endl;
|
||||
} else {
|
||||
//std::cout << recv_ << std::endl;
|
||||
// std::cout << recv_ << std::endl;
|
||||
out = recv_;
|
||||
}
|
||||
curl_slist_free_all(headers);
|
||||
@ -45,6 +45,6 @@ bool COpenAI::post(const std::string& json, std::string& out)
|
||||
size_t COpenAI::recv_call(void* contents, size_t size, size_t nmemb, std::string* output)
|
||||
{
|
||||
size_t total_size = size * nmemb;
|
||||
output->append(reinterpret_cast<char*>(contents), total_size);
|
||||
output->append(static_cast<char*>(contents), total_size);
|
||||
return total_size;
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ private:
|
||||
static size_t recv_call(void* contents, size_t size, size_t nmemb, std::string* output);
|
||||
|
||||
private:
|
||||
std::string api_key_{};
|
||||
std::string api_url_{};
|
||||
std::string recv_{};
|
||||
CURL* curl_{};
|
||||
std::string api_key_;
|
||||
std::string api_url_;
|
||||
std::string recv_;
|
||||
CURL* curl_;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user