feat(app): wire LlmClient into voice loop with trigger-prefix fallback

new module crates/jarvis-app/src/llm_fallback.rs holds an optional
LlmClient + ConversationHistory built once at startup. if GROQ_TOKEN is
unset the module logs a warning and stays disabled — voice commands keep
working as before.

both the wake-word voice path (recognize_command in app.rs) and the
gui-side text command path (process_text_command) now check whether the
recognized phrase starts with one of the configured trigger phrases
(ru: 'скажи' / 'ответь' / 'произнеси'). when it does, the remainder of
the phrase is sent to Groq and the reply is published as a new
IpcEvent::LlmReply { text } so the gui can speak it.

on api error the trailing user turn is popped from history, the russian
fallback line is sent over ipc and a 'error' voice cue plays. the loop
itself never panics.
This commit is contained in:
Bossiara13 2026-04-23 02:16:02 +03:00
parent 176f405310
commit e5aaa7e064
4 changed files with 144 additions and 3 deletions

View file

@ -250,7 +250,20 @@ fn recognize_command(
}
first_recognition = false;
if crate::llm_fallback::is_enabled() {
if let Some(prompt) = crate::llm_fallback::extract_prompt(&recognized_voice) {
crate::llm_fallback::handle(&prompt);
stt::reset_speech_recognizer();
vad_state = VadState::WaitingForVoice;
silence_frames = 0;
start = SystemTime::now();
audio_buffer.clear();
ipc::send(IpcEvent::Listening);
continue;
}
}
// filter activation phrases
// for tbr in config::ASSISTANT_PHRASES_TBR {
// recognized_voice = recognized_voice.replace(tbr, "");
@ -317,9 +330,17 @@ fn recognize_command(
fn process_text_command(text: &str, rt: &tokio::runtime::Runtime) {
info!("Processing text command: {}", text);
ipc::send(IpcEvent::SpeechRecognized { text: text.to_string() });
if crate::llm_fallback::is_enabled() {
if let Some(prompt) = crate::llm_fallback::extract_prompt(text) {
crate::llm_fallback::handle(&prompt);
ipc::send(IpcEvent::Idle);
return;
}
}
let mut filtered = text.to_lowercase();
// for tbr in config::ASSISTANT_PHRASES_TBR {
// filtered = filtered.replace(tbr, "");