Fix intent classifier init
This commit is contained in:
parent
8e830334e8
commit
b9d5f41bbd
5 changed files with 17 additions and 6 deletions
|
|
@ -99,8 +99,8 @@ fn main() -> Result<(), String> {
|
||||||
// init intent-recognition engine
|
// init intent-recognition engine
|
||||||
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
|
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
if intent::init(COMMANDS_LIST.get().unwrap()).await.is_err() {
|
if let Err(e) = intent::init(COMMANDS_LIST.get().unwrap()).await {
|
||||||
error!("Failed to initialize intent classifier");
|
error!("Failed to initialize intent classifier: {}", e);
|
||||||
app::close(1);
|
app::close(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ pub const VOSK_SPEECH_PARTIAL_WORDS: bool = false;
|
||||||
pub const INTENT_CLASSIFIER_MIN_CONFIDENCE: f64 = 0.75;
|
pub const INTENT_CLASSIFIER_MIN_CONFIDENCE: f64 = 0.75;
|
||||||
|
|
||||||
// embedding classifier
|
// embedding classifier
|
||||||
pub const EMBEDDING_MIN_CONFIDENCE: f64 = 0.60;
|
pub const EMBEDDING_MIN_CONFIDENCE: f64 = 0.70;
|
||||||
|
|
||||||
// AUDIO PROCESSING DEFAULTS
|
// AUDIO PROCESSING DEFAULTS
|
||||||
pub const DEFAULT_NOISE_SUPPRESSION: NoiseSuppressionBackend = NoiseSuppressionBackend::None;
|
pub const DEFAULT_NOISE_SUPPRESSION: NoiseSuppressionBackend = NoiseSuppressionBackend::None;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use crate::{JCommandsList, commands::JCommand, config};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use crate::config::structs::IntentRecognitionEngine;
|
use crate::config::structs::IntentRecognitionEngine;
|
||||||
|
|
||||||
|
use crate::DB;
|
||||||
|
|
||||||
static IRE_TYPE: OnceCell<IntentRecognitionEngine> = OnceCell::new();
|
static IRE_TYPE: OnceCell<IntentRecognitionEngine> = OnceCell::new();
|
||||||
|
|
||||||
pub async fn init(commands: &Vec<JCommandsList>) -> Result<(), String> {
|
pub async fn init(commands: &Vec<JCommandsList>) -> Result<(), String> {
|
||||||
|
|
@ -15,14 +17,19 @@ pub async fn init(commands: &Vec<JCommandsList>) -> Result<(), String> {
|
||||||
} // already initialized
|
} // already initialized
|
||||||
|
|
||||||
// set default ire type
|
// set default ire type
|
||||||
IRE_TYPE.set(config::DEFAULT_INTENT_RECOGNITION_ENGINE).unwrap();
|
// IRE_TYPE.set(config::DEFAULT_INTENT_RECOGNITION_ENGINE).unwrap();
|
||||||
|
|
||||||
|
// store current ire type
|
||||||
|
IRE_TYPE
|
||||||
|
.set(DB.get().unwrap().read().intent_recognition_engine)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// load given recorder
|
// load given recorder
|
||||||
match IRE_TYPE.get().unwrap() {
|
match IRE_TYPE.get().unwrap() {
|
||||||
IntentRecognitionEngine::IntentClassifier => {
|
IntentRecognitionEngine::IntentClassifier => {
|
||||||
info!("Initializing IRE backend.");
|
info!("Initializing IntentClassifier IRE backend.");
|
||||||
intentclassifier::init(&commands).await?;
|
intentclassifier::init(&commands).await?;
|
||||||
info!("IRE backend initialized.");
|
info!("IntentClassifier IRE backend initialized.");
|
||||||
},
|
},
|
||||||
IntentRecognitionEngine::EmbeddingClassifier => {
|
IntentRecognitionEngine::EmbeddingClassifier => {
|
||||||
info!("Initializing EmbeddingClassifier IRE backend.");
|
info!("Initializing EmbeddingClassifier IRE backend.");
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ pub fn init(commands: &[JCommandsList]) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// info!("{}", model_dir.display());
|
||||||
|
|
||||||
let user_model = UserDefinedEmbeddingModel {
|
let user_model = UserDefinedEmbeddingModel {
|
||||||
onnx_file: std::fs::read(model_dir.join("model.onnx"))
|
onnx_file: std::fs::read(model_dir.join("model.onnx"))
|
||||||
.map_err(|e| format!("Failed to read model.onnx: {}", e))?,
|
.map_err(|e| format!("Failed to read model.onnx: {}", e))?,
|
||||||
|
|
@ -194,6 +196,8 @@ pub fn classify(text: &str) -> Result<(String, f64), String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Embedding classify: '{}' -> '{}' ({:.2}%)", text, best_id, best_score * 100.0);
|
||||||
|
|
||||||
Ok((best_id, best_score))
|
Ok((best_id, best_score))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue