mirror of
https://github.com/m5stack/StackFlow.git
synced 2026-05-20 11:32:11 -07:00
[update] StackFlow subscriber_event_call decode_stream,delet simdjson. fix decodebase64
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
#include "StackFlow.h"
|
||||
#include "sample_log.h"
|
||||
#include <simdjson.h>
|
||||
|
||||
using namespace StackFlows;
|
||||
|
||||
@@ -33,34 +32,21 @@ llm_channel_obj::~llm_channel_obj()
|
||||
void llm_channel_obj::subscriber_event_call(const std::function<void(const std::string &, const std::string &)> &call,
|
||||
pzmq *_pzmq, const std::string &raw)
|
||||
{
|
||||
try {
|
||||
simdjson::padded_string json_string(raw);
|
||||
simdjson::ondemand::document doc;
|
||||
auto parser = _pzmq->getContextPtr<simdjson::ondemand::parser>();
|
||||
auto error = parser->iterate(json_string).get(doc);
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
std::string action;
|
||||
error = doc["action"].get_string(action);
|
||||
if (action == "inference") {
|
||||
std::string zmq_com;
|
||||
error = doc["zmq_com"].get_string(zmq_com);
|
||||
const char *user_inference_flage_str = "\"action\"";
|
||||
std::size_t pos = raw.find(user_inference_flage_str);
|
||||
while (true) {
|
||||
if (pos == std::string::npos) {
|
||||
break;
|
||||
} else if ((pos > 0) && (raw[pos - 1] != '\\')) {
|
||||
std::string zmq_com = sample_json_str_get(raw, "zmq_com");
|
||||
if (!zmq_com.empty()) set_push_url(zmq_com);
|
||||
error = doc["request_id"].get_string(request_id_);
|
||||
error = doc["work_id"].get_string(work_id_);
|
||||
request_id_ = sample_json_str_get(raw, "request_id");
|
||||
work_id_ = sample_json_str_get(raw, "work_id");
|
||||
break;
|
||||
}
|
||||
std::string object;
|
||||
error = doc["object"].get_string(object);
|
||||
auto result = doc["data"].raw_json();
|
||||
if (result.error() == simdjson::SUCCESS) {
|
||||
call(object, result.value().data());
|
||||
} else {
|
||||
std::cerr << "result: " << result.value() << "error mesg:" << result.error() << std::endl;
|
||||
}
|
||||
} catch (simdjson::simdjson_error &e) {
|
||||
std::cerr << "Error: " << simdjson::error_message(e.error()) << std::endl;
|
||||
pos = raw.find(user_inference_flage_str, pos + sizeof(user_inference_flage_str));
|
||||
}
|
||||
call(sample_json_str_get(raw, "object"), sample_json_str_get(raw, "data"));
|
||||
}
|
||||
|
||||
int llm_channel_obj::subscriber_work_id(const std::string &work_id,
|
||||
@@ -88,7 +74,6 @@ int llm_channel_obj::subscriber_work_id(const std::string &work_id,
|
||||
zmq_[id_num] = std::make_shared<pzmq>(
|
||||
subscriber_url, ZMQ_SUB,
|
||||
std::bind(&llm_channel_obj::subscriber_event_call, this, call, std::placeholders::_1, std::placeholders::_2));
|
||||
zmq_[id_num]->newContextPtr<simdjson::ondemand::parser>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "StackFlowUtil.h"
|
||||
#include <vector>
|
||||
#include "pzmq.hpp"
|
||||
#include <simdjson.h>
|
||||
|
||||
std::string StackFlows::sample_json_str_get(const std::string &json_str, const std::string &json_key)
|
||||
{
|
||||
@@ -185,9 +184,9 @@ bool StackFlows::decode_stream(const std::string &in, std::string &out,
|
||||
{
|
||||
int index = std::stoi(StackFlows::sample_json_str_get(in, "index"));
|
||||
std::string finish = StackFlows::sample_json_str_get(in, "finish");
|
||||
std::string delta = StackFlows::sample_json_str_get(in, "delta");
|
||||
stream_buff[index] = delta;
|
||||
if (finish.find("true") != std::string::npos) {
|
||||
stream_buff[index] = StackFlows::sample_json_str_get(in, "delta");
|
||||
// sample find flage: false:true
|
||||
if (finish.find("f") == std::string::npos) {
|
||||
for (size_t i = 0; i < stream_buff.size(); i++) {
|
||||
out += stream_buff.at(i);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ STATIC_FILES += [AFile('../static_lib/sherpa/ncnn/libsherpa-ncnn-core.so'),
|
||||
AFile('../static_lib/sherpa/ncnn/libkaldi-native-fbank-core.so'),
|
||||
AFile('../static_lib/libonnxruntime.so.1.14.0')
|
||||
]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'static_file',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (object.find("base64") != std::string::npos) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
@@ -26,7 +26,6 @@ REQUIREMENTS += ['ncnn', 'sherpa-ncnn-core']
|
||||
|
||||
STATIC_FILES += [AFile('sherpa-ncnn-streaming-zipformer-20M-2023-02-17.json'), AFile('sherpa-ncnn-streaming-zipformer-zh-14M-2023-02-23.json')]
|
||||
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_asr',
|
||||
'SRCS':SRCS,
|
||||
|
||||
@@ -379,7 +379,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (object.find("base64") != std::string::npos) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
@@ -27,7 +27,7 @@ REQUIREMENTS += ['ax_sys', 'ax_interpreter', 'ax_audio', 'ax_audio_3a', 'ax_fdk'
|
||||
REQUIREMENTS += ['tinyalsa', 'opus', 'samplerate', 'fdk-aac']
|
||||
|
||||
STATIC_FILES += [AFile('audio.json')]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_audio',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -33,7 +33,7 @@ LDFLAGS += ['-l:libcargs.a', '-l:libonnxruntime.a',
|
||||
|
||||
STATIC_FILES += [AFile('sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01.json'),
|
||||
AFile('sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.json')]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_kws',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -409,7 +409,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (object.find("base64") != std::string::npos) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
@@ -42,7 +42,7 @@ STATIC_FILES += [AFile('qwen2.5-0.5B-prefill-20e.json'),
|
||||
AFile('openbuddy-llama3.2-1b-ax630c_tokenizer.py'),
|
||||
AFile('qwen2.5-coder-0.5B-ax630c_tokenizer.py')
|
||||
]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_llm',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -317,7 +317,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (object.find("base64") != std::string::npos) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
@@ -27,7 +27,7 @@ INCLUDE += [ADir('../include')]
|
||||
INCLUDE += [ADir('src/runner'), ADir('../include/onnxruntime/core/session')]
|
||||
|
||||
STATIC_FILES += [AFile('melotts_zh-cn.json')]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_melotts',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -436,7 +436,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (enbase64) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
return;
|
||||
}
|
||||
next_data = &tmp_msg2;
|
||||
|
||||
@@ -28,7 +28,7 @@ INCLUDE += [ADir('src/runner/eigen-3.4.0'), ADir('src/runner/src/tn/header'), AD
|
||||
STATIC_FILES += [AFile('single_speaker_english_fast.json'),
|
||||
AFile('single_speaker_fast.json')
|
||||
]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_tts',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (enbase64) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
return;
|
||||
}
|
||||
next_data = &tmp_msg2;
|
||||
|
||||
@@ -52,7 +52,7 @@ STATIC_LIB += static_file * 4
|
||||
STATIC_FILES += [AFile('internvl2-1b-ax630c.json'),
|
||||
AFile('internvl2-1b-ax630c_tokenizer.py')
|
||||
]
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_vlm',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
std::string tmp_msg2;
|
||||
if (object.find("base64") != std::string::npos) {
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
@@ -29,7 +29,7 @@ STATIC_LIB += static_file * 2
|
||||
|
||||
STATIC_FILES += [AFile('yolo11s.json'), AFile('yolo11s-seg.json'), AFile('yolo11s-pose.json')]
|
||||
|
||||
REQUIREMENTS += ['simdjson_component']
|
||||
|
||||
env['COMPONENTS'].append({'target':'llm_yolo',
|
||||
'SRCS':SRCS,
|
||||
'INCLUDE':INCLUDE,
|
||||
|
||||
@@ -321,7 +321,7 @@ public:
|
||||
// must encode base64
|
||||
std::string tmp_msg2;
|
||||
ret = decode_base64((*next_data), tmp_msg2);
|
||||
if (!ret) {
|
||||
if (ret == -1) {
|
||||
error_body["code"] = -23;
|
||||
error_body["message"] = "Base64 decoding error.";
|
||||
send("None", "None", error_body, unit_name_);
|
||||
|
||||
Reference in New Issue
Block a user