1 //! Tauri command `chat_unload_model`: frees the chat model from memory.
2
3 use {log::debug, tauri::AppHandle};
4
5 #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
6 use {
7 super::{emit_chat_status, model_config, ENGINE},
8 crate::constants::ChatStatus,
9 log::info,
10 };
11
12 /// Unload the chat model from memory to free resources.
13 #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
14 #[tauri::command]
15 pub async fn chat_unload_model(app: AppHandle) -> Result<String, String> {
16 if ENGINE.is_loaded().await {
17 let display_name = model_config().display_name;
18 ENGINE.unload_model().await;
19 info!("Chat model unloaded: {}", display_name);
20 emit_chat_status(&app, ChatStatus::Unloaded, None, None);
21 Ok(format!("Chat model {} unloaded.", display_name))
22 } else {
23 debug!("No chat model was loaded.");
24 Ok("No chat model was loaded.".to_string())
25 }
26 }
27
28 #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
29 #[tauri::command]
30 pub async fn chat_unload_model(_app: AppHandle) -> Result<String, String> {
31 debug!("Chat model is only supported on macOS, iOS, and Android.");
32 Ok("No chat model was loaded.".to_string())
33 }