[update] format code. sys add rmmode method.

This commit is contained in:
LittleMouse
2024-12-11 14:36:42 +08:00
parent e2f8967595
commit 422ed2f4f8
11 changed files with 56 additions and 46 deletions
+2 -1
View File
@@ -92,7 +92,8 @@ public:
return -1;
}
nlohmann::json file_body;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path_, base_model_config_path_, model_);
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path_, base_model_config_path_, model_);
try {
for (auto file_name : config_file_paths) {
std::ifstream config_file(file_name);
@@ -141,7 +141,8 @@ public:
nlohmann::json error_body;
std::string base_model_path;
std::string base_model_config_path;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path, base_model_config_path, "audio");
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path, base_model_config_path, "audio");
try {
config_body = nlohmann::json::parse(data);
for (auto file_name : config_file_paths) {
+3 -2
View File
@@ -98,7 +98,8 @@ public:
}
nlohmann::json file_body;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path_, base_model_config_path_, model_);
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path_, base_model_config_path_, model_);
try {
for (auto file_name : config_file_paths) {
std::ifstream config_file(file_name);
@@ -486,7 +487,7 @@ public:
req_body["model"] = llm_task_obj->model_;
req_body["response_format"] = llm_task_obj->response_format_;
req_body["enoutput"] = llm_task_obj->enoutput_;
req_body["inputs"] = llm_task_obj->inputs_;
req_body["inputs"] = llm_task_obj->inputs_;
send("kws.taskinfo", req_body, LLM_NO_ERROR, work_id);
}
}
+3 -2
View File
@@ -85,7 +85,8 @@ public:
return -1;
}
nlohmann::json file_body;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path_, base_model_config_path_, model_);
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path_, base_model_config_path_, model_);
try {
for (auto file_name : config_file_paths) {
std::ifstream config_file(file_name);
@@ -489,7 +490,7 @@ public:
req_body["model"] = llm_task_obj->model_;
req_body["response_format"] = llm_task_obj->response_format_;
req_body["enoutput"] = llm_task_obj->enoutput_;
req_body["inputs"] = llm_task_obj->inputs_;
req_body["inputs"] = llm_task_obj->inputs_;
send("llm.taskinfo", req_body, LLM_NO_ERROR, work_id);
}
}
@@ -428,7 +428,7 @@ public:
}
next_data = &tmp_msg2;
}
std::string user_msg = sample_unescapeString(*next_data);
std::string user_msg = sample_unescapeString(*next_data);
std::vector<std::string> tmp_data = llm_task_obj->lexicon_->splitEachChar(user_msg);
for (auto cutf8 : tmp_data) {
if (is_breakpoint(cutf8)) {
@@ -160,28 +160,25 @@ int _sys_hwinfo(int com_id, const nlohmann::json &json_obj)
std::vector<ifconfig_t> ifcs;
ifconfig(ifcs);
std::vector<nlohmann::json> jifcs;
for (auto& item : ifcs)
{
for (auto &item : ifcs) {
nlohmann::json eth_info;
eth_info["name"] = item.name;
eth_info["ip"] = item.ip;
eth_info["name"] = item.name;
eth_info["ip"] = item.ip;
char eth_ip_buff[128] = {0};
sprintf(eth_ip_buff, "/sys/class/net/%s/speed", item.name);
FILE *file = fopen(eth_ip_buff, "r");
memset(eth_ip_buff, 0, sizeof(eth_ip_buff));
if(file != NULL)
{
if (file != NULL) {
int size = fread(eth_ip_buff, 1, sizeof(eth_ip_buff), file);
if(size > 0)
eth_ip_buff[size-1] = '\0';
if (size > 0) eth_ip_buff[size - 1] = '\0';
fclose(file);
}
eth_info["speed"] = eth_ip_buff;
jifcs.push_back(eth_info);
}
data_body["eth_info"] = jifcs;
out_body["data"] = data_body;
std::string out = out_body.dump();
out_body["data"] = data_body;
std::string out = out_body.dump();
zmq_com_send(com_id, out);
return 0;
}
@@ -254,6 +251,15 @@ sys_lsmode_err_1:
return out;
}
int sys_rmmode(int com_id, const nlohmann::json &json_obj)
{
std::string rmmode_name = json_obj["data"];
const std::string command = "dpkg -P llm-" + rmmode_name;
int out = system(command.c_str());
usr_print_error(json_obj["request_id"], json_obj["work_id"], "{\"code\":0, \"message\":\"\"}", com_id);
return out;
}
int sys_lstask(int com_id, const nlohmann::json &json_obj)
{
int out;
@@ -349,6 +355,7 @@ sys_update_err_1:
"{\"code\":-10, \"message\":\"Not available at the moment.\"}", com_id);
return out;
}
int sys_upgrade(int com_id, const nlohmann::json &json_obj)
{
int out;
@@ -521,6 +528,7 @@ void server_work()
key_sql["sys.reset"] = sys_reset;
key_sql["sys.reboot"] = sys_reboot;
key_sql["sys.version"] = sys_version;
key_sql["sys.rmmode"] = sys_rmmode;
}
void server_stop_work()
@@ -554,8 +562,7 @@ void unit_action_match(int com_id, const std::string &json_str)
usr_print_error("0", "sys", "{\"code\":-2, \"message\":\"json format error\"}", com_id);
return;
}
if(work_id.empty())
work_id = "sys";
if (work_id.empty()) work_id = "sys";
std::string action;
error = doc["action"].get_string(action);
if (error) {
@@ -41,8 +41,7 @@ public:
void send_data(const std::string &data)
{
if(exit_flage)
linux_uart_write(uart_fd, data.length(), (void *)data.c_str());
if (exit_flage) linux_uart_write(uart_fd, data.length(), (void *)data.c_str());
}
void reace_data_event()
@@ -55,7 +54,7 @@ public:
struct timeval timeout = {0, 500000};
if ((select(uart_fd + 1, &readfds, NULL, NULL, &timeout) <= 0) || (!FD_ISSET(uart_fd, &readfds))) continue;
ssize_t len = linux_uart_read(uart_fd, buff.size(), buff.data());
if(len <= 0) continue;
if (len <= 0) continue;
{
try {
select_json_str(std::string(buff.data(), len),
@@ -42,7 +42,7 @@ public:
void send_data(const std::string& data)
{
// tcp_server_mutex.lock();
// if (exit_flage)
// if (exit_flage)
// {
// auto tcp_channel = channel.lock();
// if(tcp_channel)
@@ -52,8 +52,7 @@ public:
// }
// tcp_server_mutex.unlock();
auto tcp_channel = channel.lock();
if(tcp_channel)
{
if (tcp_channel) {
tcp_channel->write(data);
}
}
@@ -62,7 +61,7 @@ public:
void onConnection(const SocketChannelPtr& channel)
{
if (channel->isConnected()) {
auto p_com = channel->newContextPtr<tcp_com>();
auto p_com = channel->newContextPtr<tcp_com>();
p_com->channel = channel;
p_com->work(zmq_s_format, counter_port.fetch_add(1));
if (counter_port.load() > 65535) counter_port.store(8000);
@@ -77,13 +76,12 @@ void onConnection(const SocketChannelPtr& channel)
void onMessage(const SocketChannelPtr& channel, Buffer* buf)
{
int len = (int)buf->size();
char* data = (char*)buf->data();
int len = (int)buf->size();
char* data = (char*)buf->data();
auto p_com = channel->getContextPtr<tcp_com>();
p_com->tcp_server_mutex.lock();
try {
p_com->select_json_str(std::string(data, len),
std::bind(&tcp_com::on_data, p_com, std::placeholders::_1));
p_com->select_json_str(std::string(data, len), std::bind(&tcp_com::on_data, p_com, std::placeholders::_1));
} catch (...) {
std::string out_str;
out_str += "{\"request_id\": \"0\",\"work_id\": \"sys\",\"created\": ";
@@ -9,13 +9,13 @@
int main()
{
if (access("./_tokenizer.py", F_OK) == 0) {
char *args[] = {(char*)"python3", (char*)"./_tokenizer.py", NULL};
char *args[] = {(char *)"python3", (char *)"./_tokenizer.py", NULL};
if (execvp("python3", args) == -1) {
perror("execvp");
return 1;
}
} else if (access("/opt/m5stack/share/_tokenizer.py", F_OK) == 0) {
char *args[] = {(char*)"python3", (char*)"/opt/m5stack/share/_tokenizer.py", NULL};
char *args[] = {(char *)"python3", (char *)"/opt/m5stack/share/_tokenizer.py", NULL};
if (execvp("python3", args) == -1) {
perror("execvp");
return 1;
+3 -2
View File
@@ -89,7 +89,8 @@ public:
return -1;
}
nlohmann::json file_body;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path_, base_model_config_path_, model_);
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path_, base_model_config_path_, model_);
try {
for (auto file_name : config_file_paths) {
std::ifstream config_file(file_name);
@@ -502,7 +503,7 @@ public:
req_body["model"] = llm_task_obj->model_;
req_body["response_format"] = llm_task_obj->response_format_;
req_body["enoutput"] = llm_task_obj->enoutput_;
req_body["inputs"] = llm_task_obj->inputs_;
req_body["inputs"] = llm_task_obj->inputs_;
send("vlm.taskinfo", req_body, LLM_NO_ERROR, work_id);
}
}
+13 -12
View File
@@ -89,7 +89,8 @@ public:
return -1;
}
nlohmann::json file_body;
std::list<std::string> config_file_paths = get_config_file_paths(base_model_path_, base_model_config_path_, model_);
std::list<std::string> config_file_paths =
get_config_file_paths(base_model_path_, base_model_config_path_, model_);
try {
for (auto file_name : config_file_paths) {
std::ifstream config_file(file_name);
@@ -160,7 +161,7 @@ public:
if (msg.size() != mode_config_.img_w * mode_config_.img_h * 2) {
throw std::string("img size error");
}
cv::Mat camera_data(mode_config_.img_h, mode_config_.img_w, CV_8UC2, (void *)msg.data());
cv::Mat camera_data(mode_config_.img_h, mode_config_.img_w, CV_8UC2, (void *)msg.data());
cv::Mat rgb;
cv::cvtColor(camera_data, rgb, cv::COLOR_YUV2RGB_YUYV);
return inference(rgb, false);
@@ -428,8 +429,8 @@ public:
std::string input_url_name = input + ".out_port";
std::string input_url = unit_call("sys", "sql_select", input_url_name);
if (!input_url.empty()) {
std::weak_ptr<llm_task> _llm_task_obj = llm_task_obj;
std::weak_ptr<llm_channel_obj> _llm_channel = llm_channel;
std::weak_ptr<llm_task> _llm_task_obj = llm_task_obj;
std::weak_ptr<llm_channel_obj> _llm_channel = llm_channel;
llm_channel->subscriber(
input_url, [this, _llm_task_obj, _llm_channel](pzmq *_pzmq, const std::string &raw) {
this->task_camera_data(_llm_task_obj, _llm_channel, raw);
@@ -471,16 +472,16 @@ public:
std::bind(&llm_yolo::task_user_data, this, std::weak_ptr<llm_task>(llm_task_obj),
std::weak_ptr<llm_channel_obj>(llm_channel), std::placeholders::_1, std::placeholders::_2));
llm_task_obj->inputs_.push_back(data);
} else if (data.find("camera") != std::string::npos){
} else if (data.find("camera") != std::string::npos) {
std::string input_url_name = data + ".out_port";
std::string input_url = unit_call("sys", "sql_select", input_url_name);
if (!input_url.empty()) {
std::weak_ptr<llm_task> _llm_task_obj = llm_task_obj;
std::weak_ptr<llm_channel_obj> _llm_channel = llm_channel;
llm_channel->subscriber(
input_url, [this, _llm_task_obj, _llm_channel](pzmq *_pzmq, const std::string &raw) {
this->task_camera_data(_llm_task_obj, _llm_channel, raw);
});
std::weak_ptr<llm_task> _llm_task_obj = llm_task_obj;
std::weak_ptr<llm_channel_obj> _llm_channel = llm_channel;
llm_channel->subscriber(input_url,
[this, _llm_task_obj, _llm_channel](pzmq *_pzmq, const std::string &raw) {
this->task_camera_data(_llm_task_obj, _llm_channel, raw);
});
}
llm_task_obj->inputs_.push_back(data);
}
@@ -541,7 +542,7 @@ public:
req_body["model"] = llm_task_obj->model_;
req_body["response_format"] = llm_task_obj->response_format_;
req_body["enoutput"] = llm_task_obj->enoutput_;
req_body["inputs"] = llm_task_obj->inputs_;
req_body["inputs"] = llm_task_obj->inputs_;
send("yolo.taskinfo", req_body, LLM_NO_ERROR, work_id);
}
}