mirror of
https://github.com/m5stack/StackFlow.git
synced 2026-05-20 11:32:11 -07:00
add trigger method to llm_kws
This commit is contained in:
@@ -247,6 +247,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void trigger()
|
||||
{
|
||||
if (out_callback_) {
|
||||
out_callback_("True");
|
||||
}
|
||||
}
|
||||
|
||||
bool delete_model()
|
||||
{
|
||||
spotter_.reset();
|
||||
@@ -284,6 +291,9 @@ public:
|
||||
llm_kws() : StackFlow("kws")
|
||||
{
|
||||
task_count_ = 1;
|
||||
rpc_ctx_->register_rpc_action("trigger",
|
||||
std::bind(&llm_kws::trigger, this, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
}
|
||||
|
||||
void play_awake_wav(const std::string &wav_file)
|
||||
@@ -529,6 +539,38 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string trigger(pzmq *_pzmq, const std::shared_ptr<StackFlows::pzmq_data>& rawdata0)
|
||||
{
|
||||
const std::string rawdata = rawdata0->string();
|
||||
int pos = rawdata.find("{");
|
||||
// SLOGI("llm_kws::trigger:json:%s", rawdata.substr(pos).c_str());
|
||||
|
||||
nlohmann::json error_body;
|
||||
nlohmann::json data;
|
||||
try {
|
||||
data = nlohmann::json::parse(rawdata.substr(pos));
|
||||
} catch (...) {
|
||||
SLOGE("setup json format error.");
|
||||
error_body["code"] = -2;
|
||||
error_body["message"] = "json format error.";
|
||||
send("None", "None", error_body, "kws");
|
||||
return LLM_NONE;
|
||||
}
|
||||
auto work_id = data["work_id"].get<std::string>();
|
||||
|
||||
int work_id_num = sample_get_work_id_num(work_id);
|
||||
if (llm_task_.find(work_id_num) == llm_task_.end()) {
|
||||
error_body["code"] = -6;
|
||||
error_body["message"] = "Unit Does Not Exist";
|
||||
send("None", "None", error_body, work_id);
|
||||
return LLM_NONE;
|
||||
}
|
||||
|
||||
llm_task_[work_id_num]->trigger();
|
||||
return LLM_NONE;
|
||||
}
|
||||
|
||||
|
||||
~llm_kws()
|
||||
{
|
||||
while (1) {
|
||||
|
||||
Reference in New Issue
Block a user