Skip to content

add trigger method to llm_kws #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions projects/llm_framework/main_kws/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ class llm_task {
}
}

void trigger()
{
if (out_callback_) {
out_callback_("True");
}
}

bool delete_model()
{
spotter_.reset();
Expand Down Expand Up @@ -284,6 +291,9 @@ class llm_kws : public StackFlow {
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)
Expand Down Expand Up @@ -529,6 +539,38 @@ class llm_kws : public StackFlow {
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) {
Expand Down